Return docs most similar to query using specified search type.
similarity_search(query: str, k: int = 5, where: Optional[Dict[str, str]] = None, **kwargs: Any) → List[Document][source]¶
Run a similarity search with BagelDB.
Parameters
query (str) – The query text to search for similar documents/texts.
k (int) – The number of results to return.
where (Optional[Dict[str, str]]) – Metadata filters to narrow down.
Returns
List of documents objects representing
the documents most similar to the query text.
Return type
List[Document]
similarity_search_by_vector(embedding: List[float], k: int = 5, where: Optional[Dict[str, str]] = None, **kwargs: Any) → List[Document][source]¶
Return docs most similar to embedding vector.
similarity_search_by_vector_with_relevance_scores(query_embeddings: List[float], k: int = 5, where: Optional[Dict[str, str]] = None, **kwargs: Any) → List[Tuple[Document, float]][source]¶
Return docs most similar to embedding vector and similarity score.
similarity_search_with_relevance_scores(query: str, k: int = 4, **kwargs: Any) → List[Tuple[Document, float]]¶
Return docs and relevance scores in the range [0, 1].
0 is dissimilar, 1 is most similar.
Parameters
query – input text
k – Number of Documents to return. Defaults to 4.
**kwargs – kwargs to be passed to similarity search. Should include:
score_threshold: Optional, a floating point value between 0 to 1 to
filter the resulting set of retrieved docs
Returns
List of Tuples of (doc, similarity_score)