Qdrant Vector Store for LlamaIndex
The `llama-index-vector-stores-qdrant` library provides an integration for using Qdrant as a vector store within the LlamaIndex framework. It enables users to store and retrieve vector embeddings efficiently for building Retrieval-Augmented Generation (RAG) applications. This integration supports various Qdrant features, including hybrid search capabilities, and is part of the LlamaIndex v0.10.0 ecosystem which adopted a modular architecture with separate integration packages.
Common errors
-
AttributeError: 'AsyncQdrantClient' object has no attribute 'search'
cause This typically occurs when using an incompatible version of `qdrant-client` with `llama-index-vector-stores-qdrant`. Newer `qdrant-client` versions refactored the `search` method's location or API.fixDowngrade `qdrant-client` to a compatible version (e.g., `pip install qdrant-client<1.16.0`) or upgrade `llama-index-vector-stores-qdrant` to a version that supports the newer `qdrant-client` APIs. -
ModuleNotFoundError: No module named 'llama_index.vector_stores.qdrant'
cause The `llama-index-vector-stores-qdrant` package is not installed or not correctly installed in the current environment.fixInstall the package: `pip install llama-index-vector-stores-qdrant`. -
ModuleNotFoundError: No module named 'qdrant_client'
cause The `qdrant-client` library, which is a peer dependency, is not installed.fixInstall the `qdrant-client`: `pip install qdrant-client`. -
PydanticValidationError (or similar validation error) when initializing QdrantClient with local data path.
cause This can happen with newer `qdrant-client` versions (e.g., >=1.16.0) that introduced breaking changes to the internal data model for creating collections, leading to schema validation failures.fixConstrain your `qdrant-client` version to an earlier, compatible one (e.g., `pip install qdrant-client<1.16.0`) or ensure your `llama-index-vector-stores-qdrant` version is updated to support the latest `qdrant-client` schemas.
Warnings
- breaking LlamaIndex v0.10.0 introduced a major refactor, splitting core components and integrations into separate packages. The `ServiceContext` abstraction was deprecated. This means imports and configuration patterns have changed significantly.
- breaking Future versions of `qdrant-client` (e.g., 1.16.0 as of a past issue) introduced breaking API changes (e.g., removal of `AsyncQdrantClient.search` method, Pydantic validation issues for local clients) that can cause `AttributeError` or validation failures.
- gotcha The very first retrieval query from a LlamaIndex index backed by Qdrant can be significantly slower (e.g., >10 seconds) than subsequent queries. This is due to Qdrant's internal index initialization and connection setup overhead.
- gotcha For hybrid search functionality (combining sparse and dense vectors) with Qdrant, additional dependencies like `fastembed` (for local sparse embedding generation) or `transformers` might be required.
Install
-
pip install llama-index-vector-stores-qdrant qdrant-client -
pip install llama-index-vector-stores-qdrant qdrant-client fastembed
Imports
- QdrantVectorStore
from llama_index.vector_stores.qdrant import QdrantVectorStore
- QdrantClient
from qdrant_client import QdrantClient
- AsyncQdrantClient
from qdrant_client import AsyncQdrantClient
- ServiceContext
from llama_index.service_context import ServiceContext
from llama_index.core import ServiceContext
Quickstart
import os
from llama_index.core import VectorStoreIndex, Document
from llama_index.vector_stores.qdrant import QdrantVectorStore
from qdrant_client import QdrantClient
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.core import Settings
# Ensure you have your OpenAI API key set as an environment variable
# os.environ["OPENAI_API_KEY"] = "sk-..."
# Fallback for API key or local Qdrant for quick demo without remote setup
if os.environ.get("OPENAI_API_KEY") is None or os.environ.get("OPENAI_API_KEY") == "":
print("Warning: OPENAI_API_KEY not set. Using a dummy key for example purposes. This will fail if you try to use OpenAI models.")
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "sk-dummy-key")
# Initialize Qdrant client (local in-memory for quick start, or connect to a server)
# For persistent storage, use QdrantClient(path="./qdrant_data") or connect to a running Qdrant instance
client = QdrantClient(location=":memory:") # In-memory Qdrant instance
# Create a QdrantVectorStore instance
vector_store = QdrantVectorStore(client=client, collection_name="my_documents")
# Configure LlamaIndex settings (important for v0.10+)
Settings.embed_model = OpenAIEmbedding()
# Create a dummy document
documents = [
Document(text="LlamaIndex is a data framework for LLM applications."),
Document(text="Qdrant is a vector similarity search engine."),
Document(text="Combining LlamaIndex with Qdrant enables powerful RAG systems."),
]
# Build the VectorStoreIndex
index = VectorStoreIndex.from_documents(documents, vector_store=vector_store)
# Query the index
query_engine = index.as_query_engine()
response = query_engine.query("What is LlamaIndex?")
print(f"Response: {response}")
response = query_engine.query("What is Qdrant used for?")
print(f"Response: {response}")