qdrant-haystack 4.0.0__py3-none-any.whl → 4.1.0__py3-none-any.whl

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.
@@ -39,6 +39,7 @@ class QdrantEmbeddingRetriever:
39
39
  top_k: int = 10,
40
40
  scale_score: bool = False,
41
41
  return_embedding: bool = False,
42
+ score_threshold: Optional[float] = None,
42
43
  ):
43
44
  """
44
45
  Create a QdrantEmbeddingRetriever component.
@@ -48,6 +49,10 @@ class QdrantEmbeddingRetriever:
48
49
  :param top_k: The maximum number of documents to retrieve.
49
50
  :param scale_score: Whether to scale the scores of the retrieved documents or not.
50
51
  :param return_embedding: Whether to return the embedding of the retrieved Documents.
52
+ :param score_threshold: A minimal score threshold for the result.
53
+ Score of the returned result might be higher or smaller than the threshold
54
+ depending on the `similarity` function specified in the Document Store.
55
+ E.g. for cosine similarity only higher scores will be returned.
51
56
 
52
57
  :raises ValueError: If `document_store` is not an instance of `QdrantDocumentStore`.
53
58
  """
@@ -61,6 +66,7 @@ class QdrantEmbeddingRetriever:
61
66
  self._top_k = top_k
62
67
  self._scale_score = scale_score
63
68
  self._return_embedding = return_embedding
69
+ self._score_threshold = score_threshold
64
70
 
65
71
  def to_dict(self) -> Dict[str, Any]:
66
72
  """
@@ -76,6 +82,7 @@ class QdrantEmbeddingRetriever:
76
82
  top_k=self._top_k,
77
83
  scale_score=self._scale_score,
78
84
  return_embedding=self._return_embedding,
85
+ score_threshold=self._score_threshold,
79
86
  )
80
87
  d["init_parameters"]["document_store"] = self._document_store.to_dict()
81
88
 
@@ -103,6 +110,7 @@ class QdrantEmbeddingRetriever:
103
110
  top_k: Optional[int] = None,
104
111
  scale_score: Optional[bool] = None,
105
112
  return_embedding: Optional[bool] = None,
113
+ score_threshold: Optional[float] = None,
106
114
  ):
107
115
  """
108
116
  Run the Embedding Retriever on the given input data.
@@ -112,6 +120,7 @@ class QdrantEmbeddingRetriever:
112
120
  :param top_k: The maximum number of documents to return.
113
121
  :param scale_score: Whether to scale the scores of the retrieved documents or not.
114
122
  :param return_embedding: Whether to return the embedding of the retrieved Documents.
123
+ :param score_threshold: A minimal score threshold for the result.
115
124
  :returns:
116
125
  The retrieved documents.
117
126
 
@@ -122,6 +131,7 @@ class QdrantEmbeddingRetriever:
122
131
  top_k=top_k or self._top_k,
123
132
  scale_score=scale_score or self._scale_score,
124
133
  return_embedding=return_embedding or self._return_embedding,
134
+ score_threshold=score_threshold or self._score_threshold,
125
135
  )
126
136
 
127
137
  return {"documents": docs}
@@ -161,6 +171,7 @@ class QdrantSparseEmbeddingRetriever:
161
171
  top_k: int = 10,
162
172
  scale_score: bool = False,
163
173
  return_embedding: bool = False,
174
+ score_threshold: Optional[float] = None,
164
175
  ):
165
176
  """
166
177
  Create a QdrantSparseEmbeddingRetriever component.
@@ -170,6 +181,10 @@ class QdrantSparseEmbeddingRetriever:
170
181
  :param top_k: The maximum number of documents to retrieve.
171
182
  :param scale_score: Whether to scale the scores of the retrieved documents or not.
172
183
  :param return_embedding: Whether to return the sparse embedding of the retrieved Documents.
184
+ :param score_threshold: A minimal score threshold for the result.
185
+ Score of the returned result might be higher or smaller than the threshold
186
+ depending on the Distance function used.
187
+ E.g. for cosine similarity only higher scores will be returned.
173
188
 
174
189
  :raises ValueError: If `document_store` is not an instance of `QdrantDocumentStore`.
175
190
  """
@@ -183,6 +198,7 @@ class QdrantSparseEmbeddingRetriever:
183
198
  self._top_k = top_k
184
199
  self._scale_score = scale_score
185
200
  self._return_embedding = return_embedding
201
+ self._score_threshold = score_threshold
186
202
 
187
203
  def to_dict(self) -> Dict[str, Any]:
188
204
  """
@@ -198,6 +214,7 @@ class QdrantSparseEmbeddingRetriever:
198
214
  top_k=self._top_k,
199
215
  scale_score=self._scale_score,
200
216
  return_embedding=self._return_embedding,
217
+ score_threshold=self._score_threshold,
201
218
  )
202
219
  d["init_parameters"]["document_store"] = self._document_store.to_dict()
203
220
 
@@ -225,6 +242,7 @@ class QdrantSparseEmbeddingRetriever:
225
242
  top_k: Optional[int] = None,
226
243
  scale_score: Optional[bool] = None,
227
244
  return_embedding: Optional[bool] = None,
245
+ score_threshold: Optional[float] = None,
228
246
  ):
229
247
  """
230
248
  Run the Sparse Embedding Retriever on the given input data.
@@ -234,6 +252,10 @@ class QdrantSparseEmbeddingRetriever:
234
252
  :param top_k: The maximum number of documents to return.
235
253
  :param scale_score: Whether to scale the scores of the retrieved documents or not.
236
254
  :param return_embedding: Whether to return the embedding of the retrieved Documents.
255
+ :param score_threshold: A minimal score threshold for the result.
256
+ Score of the returned result might be higher or smaller than the threshold
257
+ depending on the Distance function used.
258
+ E.g. for cosine similarity only higher scores will be returned.
237
259
  :returns:
238
260
  The retrieved documents.
239
261
 
@@ -244,6 +266,7 @@ class QdrantSparseEmbeddingRetriever:
244
266
  top_k=top_k or self._top_k,
245
267
  scale_score=scale_score or self._scale_score,
246
268
  return_embedding=return_embedding or self._return_embedding,
269
+ score_threshold=score_threshold or self._score_threshold,
247
270
  )
248
271
 
249
272
  return {"documents": docs}
@@ -288,6 +311,7 @@ class QdrantHybridRetriever:
288
311
  filters: Optional[Union[Dict[str, Any], models.Filter]] = None,
289
312
  top_k: int = 10,
290
313
  return_embedding: bool = False,
314
+ score_threshold: Optional[float] = None,
291
315
  ):
292
316
  """
293
317
  Create a QdrantHybridRetriever component.
@@ -296,6 +320,10 @@ class QdrantHybridRetriever:
296
320
  :param filters: A dictionary with filters to narrow down the search space.
297
321
  :param top_k: The maximum number of documents to retrieve.
298
322
  :param return_embedding: Whether to return the embeddings of the retrieved Documents.
323
+ :param score_threshold: A minimal score threshold for the result.
324
+ Score of the returned result might be higher or smaller than the threshold
325
+ depending on the Distance function used.
326
+ E.g. for cosine similarity only higher scores will be returned.
299
327
 
300
328
  :raises ValueError: If 'document_store' is not an instance of QdrantDocumentStore.
301
329
  """
@@ -308,6 +336,7 @@ class QdrantHybridRetriever:
308
336
  self._filters = filters
309
337
  self._top_k = top_k
310
338
  self._return_embedding = return_embedding
339
+ self._score_threshold = score_threshold
311
340
 
312
341
  def to_dict(self) -> Dict[str, Any]:
313
342
  """
@@ -322,6 +351,7 @@ class QdrantHybridRetriever:
322
351
  filters=self._filters,
323
352
  top_k=self._top_k,
324
353
  return_embedding=self._return_embedding,
354
+ score_threshold=self._score_threshold,
325
355
  )
326
356
 
327
357
  @classmethod
@@ -346,6 +376,7 @@ class QdrantHybridRetriever:
346
376
  filters: Optional[Union[Dict[str, Any], models.Filter]] = None,
347
377
  top_k: Optional[int] = None,
348
378
  return_embedding: Optional[bool] = None,
379
+ score_threshold: Optional[float] = None,
349
380
  ):
350
381
  """
351
382
  Run the Sparse Embedding Retriever on the given input data.
@@ -355,6 +386,10 @@ class QdrantHybridRetriever:
355
386
  :param filters: A dictionary with filters to narrow down the search space.
356
387
  :param top_k: The maximum number of documents to return.
357
388
  :param return_embedding: Whether to return the embedding of the retrieved Documents.
389
+ :param score_threshold: A minimal score threshold for the result.
390
+ Score of the returned result might be higher or smaller than the threshold
391
+ depending on the Distance function used.
392
+ E.g. for cosine similarity only higher scores will be returned.
358
393
  :returns:
359
394
  The retrieved documents.
360
395
 
@@ -365,6 +400,7 @@ class QdrantHybridRetriever:
365
400
  filters=filters or self._filters,
366
401
  top_k=top_k or self._top_k,
367
402
  return_embedding=return_embedding or self._return_embedding,
403
+ score_threshold=score_threshold or self._score_threshold,
368
404
  )
369
405
 
370
406
  return {"documents": docs}
@@ -111,6 +111,7 @@ class QdrantDocumentStore:
111
111
  embedding_dim: int = 768,
112
112
  on_disk: bool = False,
113
113
  use_sparse_embeddings: bool = False,
114
+ sparse_idf: bool = False,
114
115
  similarity: str = "cosine",
115
116
  return_embedding: bool = False,
116
117
  progress_bar: bool = True,
@@ -168,6 +169,9 @@ class QdrantDocumentStore:
168
169
  Whether to store the collection on disk.
169
170
  :param use_sparse_embedding:
170
171
  If set to `True`, enables support for sparse embeddings.
172
+ :param sparse_idf:
173
+ If set to `True`, computes the Inverse Document Frequency (IDF) when using sparse embeddings.
174
+ It is required to use techniques like BM42. It is ignored if `use_sparse_embeddings` is `False`.
171
175
  :param similarity:
172
176
  The similarity metric to use.
173
177
  :param return_embedding:
@@ -246,6 +250,7 @@ class QdrantDocumentStore:
246
250
  self.recreate_index = recreate_index
247
251
  self.payload_fields_to_index = payload_fields_to_index
248
252
  self.use_sparse_embeddings = use_sparse_embeddings
253
+ self.sparse_idf = use_sparse_embeddings and sparse_idf
249
254
  self.embedding_dim = embedding_dim
250
255
  self.on_disk = on_disk
251
256
  self.similarity = similarity
@@ -280,6 +285,7 @@ class QdrantDocumentStore:
280
285
  self.recreate_index,
281
286
  self.similarity,
282
287
  self.use_sparse_embeddings,
288
+ self.sparse_idf,
283
289
  self.on_disk,
284
290
  self.payload_fields_to_index,
285
291
  )
@@ -347,7 +353,9 @@ class QdrantDocumentStore:
347
353
  if not isinstance(doc, Document):
348
354
  msg = f"DocumentStore.write_documents() expects a list of Documents but got an element of {type(doc)}."
349
355
  raise ValueError(msg)
350
- self._set_up_collection(self.index, self.embedding_dim, False, self.similarity, self.use_sparse_embeddings)
356
+ self._set_up_collection(
357
+ self.index, self.embedding_dim, False, self.similarity, self.use_sparse_embeddings, self.sparse_idf
358
+ )
351
359
 
352
360
  if len(documents) == 0:
353
361
  logger.warning("Calling QdrantDocumentStore.write_documents() with empty list")
@@ -498,6 +506,7 @@ class QdrantDocumentStore:
498
506
  top_k: int = 10,
499
507
  scale_score: bool = False,
500
508
  return_embedding: bool = False,
509
+ score_threshold: Optional[float] = None,
501
510
  ) -> List[Document]:
502
511
  """
503
512
  Queries Qdrant using a sparse embedding and returns the most relevant documents.
@@ -507,6 +516,10 @@ class QdrantDocumentStore:
507
516
  :param top_k: Maximum number of documents to return.
508
517
  :param scale_score: Whether to scale the scores of the retrieved documents.
509
518
  :param return_embedding: Whether to return the embeddings of the retrieved documents.
519
+ :param score_threshold: A minimal score threshold for the result.
520
+ Score of the returned result might be higher or smaller than the threshold
521
+ depending on the Distance function used.
522
+ E.g. for cosine similarity only higher scores will be returned.
510
523
 
511
524
  :returns: List of documents that are most similar to `query_sparse_embedding`.
512
525
 
@@ -536,6 +549,7 @@ class QdrantDocumentStore:
536
549
  query_filter=qdrant_filters,
537
550
  limit=top_k,
538
551
  with_vectors=return_embedding,
552
+ score_threshold=score_threshold,
539
553
  )
540
554
  results = [
541
555
  convert_qdrant_point_to_haystack_document(point, use_sparse_embeddings=self.use_sparse_embeddings)
@@ -555,6 +569,7 @@ class QdrantDocumentStore:
555
569
  top_k: int = 10,
556
570
  scale_score: bool = False,
557
571
  return_embedding: bool = False,
572
+ score_threshold: Optional[float] = None,
558
573
  ) -> List[Document]:
559
574
  """
560
575
  Queries Qdrant using a dense embedding and returns the most relevant documents.
@@ -564,6 +579,10 @@ class QdrantDocumentStore:
564
579
  :param top_k: Maximum number of documents to return.
565
580
  :param scale_score: Whether to scale the scores of the retrieved documents.
566
581
  :param return_embedding: Whether to return the embeddings of the retrieved documents.
582
+ :param score_threshold: A minimal score threshold for the result.
583
+ Score of the returned result might be higher or smaller than the threshold
584
+ depending on the Distance function used.
585
+ E.g. for cosine similarity only higher scores will be returned.
567
586
 
568
587
  :returns: List of documents that are most similar to `query_embedding`.
569
588
  """
@@ -578,6 +597,7 @@ class QdrantDocumentStore:
578
597
  query_filter=qdrant_filters,
579
598
  limit=top_k,
580
599
  with_vectors=return_embedding,
600
+ score_threshold=score_threshold,
581
601
  )
582
602
  results = [
583
603
  convert_qdrant_point_to_haystack_document(point, use_sparse_embeddings=self.use_sparse_embeddings)
@@ -600,6 +620,7 @@ class QdrantDocumentStore:
600
620
  filters: Optional[Union[Dict[str, Any], rest.Filter]] = None,
601
621
  top_k: int = 10,
602
622
  return_embedding: bool = False,
623
+ score_threshold: Optional[float] = None,
603
624
  ) -> List[Document]:
604
625
  """
605
626
  Retrieves documents based on dense and sparse embeddings and fuses the results using Reciprocal Rank Fusion.
@@ -612,6 +633,10 @@ class QdrantDocumentStore:
612
633
  :param filters: Filters applied to the retrieved documents.
613
634
  :param top_k: Maximum number of documents to return.
614
635
  :param return_embedding: Whether to return the embeddings of the retrieved documents.
636
+ :param score_threshold: A minimal score threshold for the result.
637
+ Score of the returned result might be higher or smaller than the threshold
638
+ depending on the Distance function used.
639
+ E.g. for cosine similarity only higher scores will be returned.
615
640
 
616
641
  :returns: List of Document that are most similar to `query_embedding` and `query_sparse_embedding`.
617
642
 
@@ -642,6 +667,7 @@ class QdrantDocumentStore:
642
667
  limit=top_k,
643
668
  with_payload=True,
644
669
  with_vector=return_embedding,
670
+ score_threshold=score_threshold,
645
671
  )
646
672
 
647
673
  dense_request = rest.SearchRequest(
@@ -714,6 +740,7 @@ class QdrantDocumentStore:
714
740
  recreate_collection: bool,
715
741
  similarity: str,
716
742
  use_sparse_embeddings: bool,
743
+ sparse_idf: bool,
717
744
  on_disk: bool = False,
718
745
  payload_fields_to_index: Optional[List[dict]] = None,
719
746
  ):
@@ -729,6 +756,8 @@ class QdrantDocumentStore:
729
756
  The similarity measure to use.
730
757
  :param use_sparse_embeddings:
731
758
  Whether to use sparse embeddings.
759
+ :param sparse_idf:
760
+ Whether to compute the Inverse Document Frequency (IDF) when using sparse embeddings. Required for BM42.
732
761
  :param on_disk:
733
762
  Whether to store the collection on disk.
734
763
  :param payload_fields_to_index:
@@ -745,7 +774,9 @@ class QdrantDocumentStore:
745
774
  if recreate_collection or not self.client.collection_exists(collection_name):
746
775
  # There is no need to verify the current configuration of that
747
776
  # collection. It might be just recreated again or does not exist yet.
748
- self.recreate_collection(collection_name, distance, embedding_dim, on_disk, use_sparse_embeddings)
777
+ self.recreate_collection(
778
+ collection_name, distance, embedding_dim, on_disk, use_sparse_embeddings, sparse_idf
779
+ )
749
780
  # Create Payload index if payload_fields_to_index is provided
750
781
  self._create_payload_index(collection_name, payload_fields_to_index)
751
782
  return
@@ -808,6 +839,7 @@ class QdrantDocumentStore:
808
839
  embedding_dim: int,
809
840
  on_disk: Optional[bool] = None,
810
841
  use_sparse_embeddings: Optional[bool] = None,
842
+ sparse_idf: bool = False,
811
843
  ):
812
844
  """
813
845
  Recreates the Qdrant collection with the specified parameters.
@@ -822,6 +854,8 @@ class QdrantDocumentStore:
822
854
  Whether to store the collection on disk.
823
855
  :param use_sparse_embeddings:
824
856
  Whether to use sparse embeddings.
857
+ :param sparse_idf:
858
+ Whether to compute the Inverse Document Frequency (IDF) when using sparse embeddings. Required for BM42.
825
859
  """
826
860
  if on_disk is None:
827
861
  on_disk = self.on_disk
@@ -840,7 +874,8 @@ class QdrantDocumentStore:
840
874
  SPARSE_VECTORS_NAME: rest.SparseVectorParams(
841
875
  index=rest.SparseIndexParams(
842
876
  on_disk=on_disk,
843
- )
877
+ ),
878
+ modifier=rest.Modifier.IDF if sparse_idf else None,
844
879
  ),
845
880
  }
846
881
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qdrant-haystack
3
- Version: 4.0.0
3
+ Version: 4.1.0
4
4
  Summary: An integration of Qdrant ANN vector database backend with Haystack
5
5
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations
6
6
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/qdrant/README.md
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
20
  Requires-Python: >=3.8
21
21
  Requires-Dist: haystack-ai>=2.0.1
22
- Requires-Dist: qdrant-client
22
+ Requires-Dist: qdrant-client>=1.10.0
23
23
  Description-Content-Type: text/markdown
24
24
 
25
25
  # qdrant-haystack
@@ -1,11 +1,11 @@
1
1
  haystack_integrations/components/retrievers/qdrant/__init__.py,sha256=IRjcM4f8b5eKFEMn8tn6h6RrfslEGP3WafU7mrzNzQM,313
2
- haystack_integrations/components/retrievers/qdrant/retriever.py,sha256=_6noYJ0M71shgoTOywIgSuGQtB-CBhwRW_zUFiYIOTw,13465
2
+ haystack_integrations/components/retrievers/qdrant/retriever.py,sha256=acSMsrtVbkU1xpihH6oeIaKy6SGnQvzERZ3TWJvUViY,15826
3
3
  haystack_integrations/document_stores/qdrant/__init__.py,sha256=kUGc5uewqArhmVR-JqB_NmJ4kNkTIQIvYDNSoO2ELn0,302
4
4
  haystack_integrations/document_stores/qdrant/converters.py,sha256=2hcuI3kty1dVHzX1WGXxEtlrnZ9E8TAG56XATCFa6Pw,2491
5
- haystack_integrations/document_stores/qdrant/document_store.py,sha256=mjzv6Z3iE9oFRil_PVLjmEq-vX7a7ULpT5afGsU7iSU,36088
5
+ haystack_integrations/document_stores/qdrant/document_store.py,sha256=eLw4P1h8GCj40R-BIlQOvJG9MpDzvtmQ7Hpb3AZhMSo,38117
6
6
  haystack_integrations/document_stores/qdrant/filters.py,sha256=0w70Wa3Za1fNdbJ5O95sZDIpXfblJG_sBBUv0JTQ0-o,8337
7
7
  haystack_integrations/document_stores/qdrant/migrate_to_sparse.py,sha256=i6wBC_9_JVzYZtqKm3dhHKTxhwNdcAdpgki8GABDp1c,4909
8
- qdrant_haystack-4.0.0.dist-info/METADATA,sha256=wHvVJIDCQDPFLX8fL_d11zNMZul4U6r02bVhhCdmitk,1862
9
- qdrant_haystack-4.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
- qdrant_haystack-4.0.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
11
- qdrant_haystack-4.0.0.dist-info/RECORD,,
8
+ qdrant_haystack-4.1.0.dist-info/METADATA,sha256=wGNRbZYtVJ3BbHH22ZsoVhGGtyCR3cNeozFKHiAsYjI,1870
9
+ qdrant_haystack-4.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
+ qdrant_haystack-4.1.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
11
+ qdrant_haystack-4.1.0.dist-info/RECORD,,