Skip to content

Commit

Permalink
Fixed proximity search
Browse files Browse the repository at this point in the history
  • Loading branch information
robkorn committed Sep 8, 2023
1 parent c2eafd0 commit 2ed0e7c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::data_tags::{DataTag, DataTagIndex};
use crate::embeddings::Embedding;
use crate::model_type::{EmbeddingModelType, RemoteModel};
use crate::resource_errors::VectorResourceError;
use crate::vector_resource::{DataChunk, DataContent, RetrievedDataChunk, VectorResource};
use crate::vector_resource::{DataChunk, DataContent, RetrievedDataChunk, TraversalMethod, VectorResource};
use serde_json;
use std::collections::HashMap;

Expand Down Expand Up @@ -140,12 +140,14 @@ impl DocumentVectorResource {
/// Performs a vector search using a query embedding, and then
/// fetches a specific number of DataChunks below and above the most
/// similar DataChunk.
///
/// Does not traverse past the top level.
pub fn vector_search_proximity(
&self,
query: Embedding,
proximity_window: u64,
) -> Result<Vec<RetrievedDataChunk>, VectorResourceError> {
let search_results = self.vector_search(query, 1);
let search_results = self.vector_search_with_traversal(query, 1, &TraversalMethod::UntilDepth(0));
let most_similar_chunk = search_results.first().ok_or(VectorResourceError::VectorResourceEmpty)?;
let most_similar_id = most_similar_chunk
.chunk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum TraversalMethod {
Efficient,
/// Efficiently traverses until (and including) the specified depth is hit (or until there are no more levels to go).
/// Will return BaseVectorResource DataChunks if they are the highest scored at the specified depth.
/// Top level starts at 0, and so first level of depth into internal BaseVectorResources is thus 1.
UntilDepth(u64),
/// Does not skip over any DataChunks, traverses through all levels.
Exhaustive,
Expand Down

0 comments on commit 2ed0e7c

Please sign in to comment.