|
|
|
@ -185,6 +185,7 @@ class FAISS(VectorStore):
|
|
|
|
|
k: int = 4,
|
|
|
|
|
filter: Optional[Dict[str, Any]] = None,
|
|
|
|
|
fetch_k: int = 20,
|
|
|
|
|
**kwargs: Any,
|
|
|
|
|
) -> List[Tuple[Document, float]]:
|
|
|
|
|
"""Return docs most similar to query.
|
|
|
|
|
|
|
|
|
@ -194,6 +195,9 @@ class FAISS(VectorStore):
|
|
|
|
|
filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.
|
|
|
|
|
fetch_k: (Optional[int]) Number of Documents to fetch before filtering.
|
|
|
|
|
Defaults to 20.
|
|
|
|
|
**kwargs: kwargs to be passed to similarity search. Can include:
|
|
|
|
|
score_threshold: Optional, a floating point value between 0 to 1 to
|
|
|
|
|
filter the resulting set of retrieved docs
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
List of documents most similar to the query text and L2 distance
|
|
|
|
@ -218,6 +222,14 @@ class FAISS(VectorStore):
|
|
|
|
|
docs.append((doc, scores[0][j]))
|
|
|
|
|
else:
|
|
|
|
|
docs.append((doc, scores[0][j]))
|
|
|
|
|
|
|
|
|
|
score_threshold = kwargs.get("score_threshold")
|
|
|
|
|
if score_threshold is not None:
|
|
|
|
|
docs = [
|
|
|
|
|
(doc, similarity)
|
|
|
|
|
for doc, similarity in docs
|
|
|
|
|
if similarity >= score_threshold
|
|
|
|
|
]
|
|
|
|
|
return docs[:k]
|
|
|
|
|
|
|
|
|
|
def similarity_search_with_score(
|
|
|
|
|