faiss-haystack 3.0.1__tar.gz → 3.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/CHANGELOG.md +7 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/PKG-INFO +1 -1
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/src/haystack_integrations/document_stores/faiss/document_store.py +26 -24
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/tests/test_document_store.py +11 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/.gitignore +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/LICENSE.txt +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/README.md +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/pydoc/config_docusaurus.yml +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/pyproject.toml +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/src/haystack_integrations/components/retrievers/faiss/__init__.py +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/src/haystack_integrations/components/retrievers/faiss/embedding_retriever.py +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/src/haystack_integrations/components/retrievers/py.typed +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/src/haystack_integrations/document_stores/faiss/__init__.py +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/src/haystack_integrations/document_stores/py.typed +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/tests/__init__.py +0 -0
- {faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/tests/test_embedding_retriever.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: faiss-haystack
|
|
3
|
-
Version: 3.0
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: An integration of FAISS (library for efficient similarity search of dense vectors) with Haystack
|
|
5
5
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/faiss#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
@@ -246,41 +246,43 @@ class FAISSDocumentStore:
|
|
|
246
246
|
# Ensure embedding format
|
|
247
247
|
query_vec = np.array([query_embedding], dtype="float32")
|
|
248
248
|
|
|
249
|
-
#
|
|
250
|
-
#
|
|
251
|
-
#
|
|
252
|
-
#
|
|
253
|
-
|
|
249
|
+
# Filters are checked in Python on the documents, so they are applied to the FAISS hits (post-filtering).
|
|
250
|
+
# If too few of the fetched neighbours match the filters, search once more over the whole index, so matching
|
|
251
|
+
# documents further away are not missed. One full search is cheaper than growing k step by step: exhaustive
|
|
252
|
+
# indexes like "Flat" compare against every vector whatever k is, and each retry re-filters the same hits.
|
|
254
253
|
fetch_k = top_k
|
|
255
254
|
if filters:
|
|
256
|
-
fetch_k = min(self.index.ntotal, top_k * 10)
|
|
255
|
+
fetch_k = min(self.index.ntotal, top_k * 10)
|
|
257
256
|
|
|
258
|
-
|
|
257
|
+
while True:
|
|
258
|
+
distances, indices = self.index.search(query_vec, fetch_k)
|
|
259
259
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
results = []
|
|
261
|
+
for dist, int_id in zip(distances[0], indices[0], strict=False):
|
|
262
|
+
if int_id == -1:
|
|
263
|
+
continue
|
|
264
264
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
doc_id = self.id_map.get(int_id)
|
|
266
|
+
if not doc_id or doc_id not in self.documents:
|
|
267
|
+
continue
|
|
268
268
|
|
|
269
|
-
|
|
269
|
+
doc = self.documents[doc_id]
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
if filters and not self._matches_filters(doc, filters):
|
|
272
|
+
continue
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
# Build a new instance instead of mutating score in place.
|
|
275
|
+
score = float(1 / (1 + dist)) if self.index_string == "Flat" else float(dist)
|
|
276
|
+
result_doc = replace(doc, score=score)
|
|
277
277
|
|
|
278
|
-
|
|
278
|
+
results.append(result_doc)
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
if len(results) >= top_k:
|
|
281
|
+
break
|
|
282
282
|
|
|
283
|
-
|
|
283
|
+
if not filters or len(results) >= top_k or fetch_k >= self.index.ntotal:
|
|
284
|
+
return results
|
|
285
|
+
fetch_k = self.index.ntotal
|
|
284
286
|
|
|
285
287
|
def _check_condition(self, doc: Document, condition: dict[str, Any]) -> bool:
|
|
286
288
|
if "operator" not in condition and "conditions" not in condition:
|
|
@@ -85,6 +85,17 @@ class TestFAISSDocumentStoreUnit:
|
|
|
85
85
|
with pytest.raises(FilterError, match=error_match):
|
|
86
86
|
ds.filter_documents(filters=filters)
|
|
87
87
|
|
|
88
|
+
def test_search_with_filters_finds_match_outside_first_candidates(self):
|
|
89
|
+
# The only matching document is the farthest one, outside the first `top_k * 10` neighbours.
|
|
90
|
+
ds = FAISSDocumentStore(embedding_dim=2)
|
|
91
|
+
docs = [Document(id=f"en{i}", embedding=[1.0, i / 100], meta={"lang": "en"}) for i in range(30)]
|
|
92
|
+
docs.append(Document(id="de", embedding=[-1.0, 0.0], meta={"lang": "de"}))
|
|
93
|
+
ds.write_documents(docs)
|
|
94
|
+
|
|
95
|
+
results = ds.search([1.0, 0.0], top_k=1, filters={"field": "meta.lang", "operator": "==", "value": "de"})
|
|
96
|
+
|
|
97
|
+
assert [doc.id for doc in results] == ["de"]
|
|
98
|
+
|
|
88
99
|
|
|
89
100
|
@pytest.mark.integration
|
|
90
101
|
class TestFAISSDocumentStore(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{faiss_haystack-3.0.1 → faiss_haystack-3.1.0}/src/haystack_integrations/document_stores/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|