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 | | | 13 | :------------ | :--------------------------------------------------------------------------------------- | 14 | API reference | [Qdrant](/reference/integrations-qdrant) | 15 | GitHub link | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/qdrant | 16 17 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. 18 19 ### Installation 20 21 You can simply install the Qdrant Haystack integration with: 22 23 ```shell 24 pip install qdrant-haystack 25 ``` 26 27 ### Initialization 28 29 The quickest way to use `QdrantDocumentStore` is to create an in-memory instance of it: 30 31 ```python 32 from haystack.dataclasses.document import Document 33 from haystack_integrations.document_stores.qdrant import QdrantDocumentStore 34 35 document_store = QdrantDocumentStore( 36 ":memory:", 37 recreate_index=True, 38 return_embedding=True, 39 wait_result_from_api=True, 40 ) 41 document_store.write_documents( 42 [ 43 Document(content="This is first", embedding=[0.0] * 5), 44 Document(content="This is second", embedding=[0.1, 0.2, 0.3, 0.4, 0.5]), 45 ], 46 ) 47 print(document_store.count_documents()) 48 ``` 49 50 :::warning 51 Collections Created Outside Haystack 52 53 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. 54 ::: 55 56 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: 57 58 ```python 59 from haystack.dataclasses.document import Document 60 from haystack_integrations.document_stores.qdrant import QdrantDocumentStore 61 from haystack.utils import Secret 62 63 document_store = QdrantDocumentStore( 64 url="https://XXXXXXXXX.us-east4-0.gcp.cloud.qdrant.io:6333", 65 index="your_index_name", 66 embedding_dim=1024, # based on the embedding model 67 recreate_index=True, # enable only to recreate the index and not connect to the existing one 68 api_key=Secret.from_token("YOUR_TOKEN"), 69 ) 70 71 document_store.write_documents( 72 [ 73 Document(content="This is first", embedding=[0.0] * 5), 74 Document(content="This is second", embedding=[0.1, 0.2, 0.3, 0.4, 0.5]), 75 ], 76 ) 77 print(document_store.count_documents()) 78 ``` 79 80 :::tip 81 More information 82 83 You can find more ways to initialize and use QdrantDocumentStore on our [integration page](https://haystack.deepset.ai/integrations/qdrant-document-store). 84 ::: 85 86 ### Supported Retrievers 87 88 - [`QdrantEmbeddingRetriever`](../pipeline-components/retrievers/qdrantembeddingretriever.mdx): Retrieves documents from the `QdrantDocumentStore` based on their dense embeddings (vectors). 89 - [`QdrantSparseEmbeddingRetriever`](../pipeline-components/retrievers/qdrantsparseembeddingretriever.mdx): Retrieves documents from the `QdrantDocumentStore` based on their sparse embeddings. 90 - [`QdrantHybridRetriever`](../pipeline-components/retrievers/qdranthybridretriever.mdx): Retrieves documents from the `QdrantDocumentStore` based on both dense and sparse embeddings. 91 92 :::note 93 Sparse Embedding Support 94 95 To use Sparse Embedding support, you need to initialize the `QdrantDocumentStore` with `use_sparse_embeddings=True`, which is `False` by default. 96 97 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. 98 ::: 99 100 ## Additional References 101 102 🧑🍳 Cookbook: [Sparse Embedding Retrieval with Qdrant and FastEmbed](https://haystack.deepset.ai/cookbook/sparse_embedding_retrieval)