Skip to content

Use Qdrant with LlamaIndex

View as Markdown

LlamaIndex connects your private data to language models. Use your Qdrant database as its vector store to index documents and query them.

You need a Running database with its Endpoint URL and API Key; see Connect to a vector database. You need Python 3.8 or later and a folder of documents.

pip install llama-index llama-index-vector-stores-qdrant qdrant-client

<your-endpoint-url> is the Endpoint URL and <your-api-key> is your API key. <your-data-dir> is the folder of documents. <collection_name> is the collection that stores them. <your-query> is the question to ask.

import qdrant_client
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext, Settings
from llama_index.vector_stores.qdrant import QdrantVectorStore
from llama_index.embeddings.fastembed import FastEmbedEmbedding
# Configure the embedding model
Settings.embed_model = FastEmbedEmbedding(model_name="BAAI/bge-base-en-v1.5")
Settings.llm = None
# Load documents
documents = SimpleDirectoryReader("<your-data-dir>").load_data()
# Connect and insert into Qdrant
client = qdrant_client.QdrantClient(
host="<your-endpoint-url>", port=6333, api_key="<your-api-key>"
)
vector_store = QdrantVectorStore(client=client, collection_name="<collection_name>")
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
# Query
query_engine = index.as_query_engine()
response = query_engine.query("<your-query>")

For more, see the Qdrant LlamaIndex documentation. To create the embeddings with the TIR GenAI API, see Generate vector embeddings. If a connection fails, see Troubleshooting Vector Database.