Max marginal relecance search fails if there are not enough docs (#1117)

Implementation fails if there are not enough documents. Added the same
check as used for similarity search.

Current implementation raises
```  
File ".venv/lib/python3.9/site-packages/langchain/vectorstores/faiss.py", line 160, in max_marginal_relevance_search
    _id = self.index_to_docstore_id[i]
KeyError: -1
```
searx-api
Tom Bocklisch 1 year ago committed by GitHub
parent 511d41114f
commit 47c3221fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -189,6 +189,9 @@ class FAISS(VectorStore):
docs = []
for i in selected_indices:
_id = self.index_to_docstore_id[i]
if _id == -1:
# This happens when not enough docs are returned.
continue
doc = self.docstore.search(_id)
if not isinstance(doc, Document):
raise ValueError(f"Could not find document for id {_id}, got {doc}")

Loading…
Cancel
Save