qdrant-document-store.mdx
1 --- 2 title: "QdrantDocumentStore" 3 id: qdrant-document-store 4 slug: "/qdrant-document-store" 5 description: "Use the Qdrant vector database with Haystack." 6 --- 7 8 # QdrantDocumentStore 9 10 Use the Qdrant vector database with Haystack. 11 12 <div className="key-value-table"> 13 14 | | | 15 | --- | --- | 16 | API reference | [Qdrant](/reference/integrations-qdrant) | 17 | GitHub link | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/qdrant | 18 19 </div> 20 21 Qdrant is a powerful high-performance, massive-scale vector database. The `QdrantDocumentStore` can be used with any Qdrant instance, in-memory, locally persisted, hosted, and the official Qdrant Cloud. 22 23 ### Installation 24 25 You can simply install the Qdrant Haystack integration with: 26 27 ```shell 28 pip install qdrant-haystack 29 ``` 30 31 ### Initialization 32 33 The quickest way to use `QdrantDocumentStore` is to create an in-memory instance of it: 34 35 ```python 36 from haystack.dataclasses.document import Document 37 from haystack_integrations.document_stores.qdrant import QdrantDocumentStore 38 39 document_store = QdrantDocumentStore( 40 ":memory:", 41 recreate_index=True, 42 return_embedding=True, 43 wait_result_from_api=True, 44 ) 45 document_store.write_documents( 46 [ 47 Document(content="This is first", embedding=[0.0] * 5), 48 Document(content="This is second", embedding=[0.1, 0.2, 0.3, 0.4, 0.5]), 49 ], 50 ) 51 print(document_store.count_documents()) 52 ``` 53 54 :::warning[Collections Created Outside Haystack] 55 56 When you create a `QdrantDocumentStore` instance, Haystack takes care of setting up the collection. In general, you cannot use a Qdrant collection created without Haystack with Haystack. If you want to migrate your existing collection, see the sample script at https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/qdrant/src/haystack_integrations/document_stores/qdrant/migrate_to_sparse.py. 57 ::: 58 59 You can also connect directly to [Qdrant Cloud](https://cloud.qdrant.io/login) directly. Once you have your API key and your cluster URL from the Qdrant dashboard, you can connect like this: 60 61 ```python 62 from haystack.dataclasses.document import Document 63 from haystack_integrations.document_stores.qdrant import QdrantDocumentStore 64 from haystack.utils import Secret 65 66 document_store = QdrantDocumentStore( 67 url="https://XXXXXXXXX.us-east4-0.gcp.cloud.qdrant.io:6333", 68 index="your_index_name", 69 embedding_dim=1024, # based on the embedding model 70 recreate_index=True, # enable only to recreate the index and not connect to the existing one 71 api_key=Secret.from_token("YOUR_TOKEN"), 72 ) 73 74 document_store.write_documents( 75 [ 76 Document(content="This is first", embedding=[0.0] * 5), 77 Document(content="This is second", embedding=[0.1, 0.2, 0.3, 0.4, 0.5]), 78 ], 79 ) 80 print(document_store.count_documents()) 81 ``` 82 83 :::tip[More information] 84 85 You can find more ways to initialize and use QdrantDocumentStore on our [integration page](https://haystack.deepset.ai/integrations/qdrant-document-store). 86 ::: 87 88 ### Supported Retrievers 89 90 - [`QdrantEmbeddingRetriever`](../pipeline-components/retrievers/qdrantembeddingretriever.mdx): Retrieves documents from the `QdrantDocumentStore` based on their dense embeddings (vectors). 91 - [`QdrantSparseEmbeddingRetriever`](../pipeline-components/retrievers/qdrantsparseembeddingretriever.mdx): Retrieves documents from the `QdrantDocumentStore` based on their sparse embeddings. 92 - [`QdrantHybridRetriever`](../pipeline-components/retrievers/qdranthybridretriever.mdx): Retrieves documents from the `QdrantDocumentStore` based on both dense and sparse embeddings. 93 94 :::note[Sparse Embedding Support] 95 96 To use Sparse Embedding support, you need to initialize the `QdrantDocumentStore` with `use_sparse_embeddings=True`, which is `False` by default. 97 98 If you want to use Document Store or collection previously created with this feature disabled, you must migrate the existing data. You can do this by taking advantage of the `migrate_to_sparse_embeddings_support` utility function. 99 ::: 100 101 ## Additional References 102 103 🧑🍳 Cookbook: [Sparse Embedding Retrieval with Qdrant and FastEmbed](https://haystack.deepset.ai/cookbook/sparse_embedding_retrieval)