SKILL.md
SKILL.mdBrowse 3 files
3,388 tokens
13,781 bytes
Token encoding: o200k_base
Snapshot 24fd22b
1---2name: qdrant3description: Vector search engine for production RAG systems.4version: 1.0.15author: Orchestra Research6license: MIT7dependencies: [qdrant-client>=1.14.0]8platforms: [linux, macos, windows]9metadata:10 hermes:11 tags: [RAG, Vector Search, Qdrant, Semantic Search, Embeddings, Similarity Search, HNSW, Production, Distributed]12 13---14 15# Qdrant - Vector Similarity Search Engine16 17High-performance vector database written in Rust for production RAG and semantic search.18 19## When to use Qdrant20 21**Use Qdrant when:**22- Building production RAG systems requiring low latency23- Need hybrid search (vectors + metadata filtering)24- Require horizontal scaling with sharding/replication25- Want on-premise deployment with full data control26- Need multi-vector storage per record (dense + sparse)27- Building real-time recommendation systems28 29**Key features:**30- **Rust-powered**: Memory-safe, high performance31- **Rich filtering**: Filter by any payload field during search32- **Multiple vectors**: Dense, sparse, multi-dense per point33- **Quantization**: Scalar, product, binary for memory efficiency34- **Distributed**: Raft consensus, sharding, replication35- **REST + gRPC**: Both APIs with full feature parity36 37**Use alternatives instead:**38- **Chroma**: Simpler setup, embedded use cases39- **FAISS**: Maximum raw speed, research/batch processing40- **Pinecone**: Fully managed, zero ops preferred41- **Weaviate**: GraphQL preference, built-in vectorizers42 43## Quick start44 45### Installation46 47```bash48# Python client49pip install qdrant-client50 51# Docker (recommended for development)52docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant53 54# Docker with persistent storage55docker run -p 6333:6333 -p 6334:6334 \56 -v $(pwd)/qdrant_storage:/qdrant/storage \57 qdrant/qdrant58```59 60### Basic usage61 62```python63from qdrant_client import QdrantClient64from qdrant_client.models import Distance, VectorParams, PointStruct65 66# Connect to Qdrant67client = QdrantClient(host="localhost", port=6333)68 69# Create collection70client.create_collection(71 collection_name="documents",72 vectors_config=VectorParams(size=384, distance=Distance.COSINE)73)74 75# Insert vectors with payload76client.upsert(77 collection_name="documents",78 points=[79 PointStruct(80 id=1,81 vector=[0.1, 0.2, ...], # 384-dim vector82 payload={"title": "Doc 1", "category": "tech"}83 ),84 PointStruct(85 id=2,86 vector=[0.3, 0.4, ...],87 payload={"title": "Doc 2", "category": "science"}88 )89 ]90)91 92# Search with filtering (query_points is the current API; client.search is removed in qdrant-client 1.14+)93response = client.query_points(94 collection_name="documents",95 query=[0.15, 0.25, ...],96 query_filter={97 "must": [{"key": "category", "match": {"value": "tech"}}]98 },99 limit=10100)101 102for point in response.points:103 print(f"ID: {point.id}, Score: {point.score}, Payload: {point.payload}")104```105 106## Core concepts107 108### Points - Basic data unit109 110```python111from qdrant_client.models import PointStruct112 113# Point = ID + Vector(s) + Payload114point = PointStruct(115 id=123, # Integer or UUID string116 vector=[0.1, 0.2, 0.3, ...], # Dense vector117 payload={ # Arbitrary JSON metadata118 "title": "Document title",119 "category": "tech",120 "timestamp": 1699900000,121 "tags": ["python", "ml"]122 }123)124 125# Batch upsert (recommended)126client.upsert(127 collection_name="documents",128 points=[point1, point2, point3],129 wait=True # Wait for indexing130)131```132 133### Collections - Vector containers134 135```python136from qdrant_client.models import VectorParams, Distance, HnswConfigDiff137 138# Create with HNSW configuration139client.create_collection(140 collection_name="documents",141 vectors_config=VectorParams(142 size=384, # Vector dimensions143 distance=Distance.COSINE # COSINE, EUCLID, DOT, MANHATTAN144 ),145 hnsw_config=HnswConfigDiff(146 m=16, # Connections per node (default 16)147 ef_construct=100, # Build-time accuracy (default 100)148 full_scan_threshold=10000 # Switch to brute force below this149 ),150 on_disk_payload=True # Store payload on disk151)152 153# Collection info154info = client.get_collection("documents")155print(f"Points: {info.points_count}, Vectors: {info.vectors_count}")156```157 158### Distance metrics159 160| Metric | Use Case | Range |161|--------|----------|-------|162| `COSINE` | Text embeddings, normalized vectors | 0 to 2 |163| `EUCLID` | Spatial data, image features | 0 to ∞ |164| `DOT` | Recommendations, unnormalized | -∞ to ∞ |165| `MANHATTAN` | Sparse features, discrete data | 0 to ∞ |166 167## Search operations168 169### Basic search170 171```python172# Simple nearest neighbor search (returns a QueryResponse; use .points)173response = client.query_points(174 collection_name="documents",175 query=[0.1, 0.2, ...],176 limit=10,177 with_payload=True,178 with_vectors=False # Don't return vectors (faster)179)180results = response.points181```182 183### Filtered search184 185```python186from qdrant_client.models import Filter, FieldCondition, MatchValue, Range187 188# Complex filtering189response = client.query_points(190 collection_name="documents",191 query=query_embedding,192 query_filter=Filter(193 must=[194 FieldCondition(key="category", match=MatchValue(value="tech")),195 FieldCondition(key="timestamp", range=Range(gte=1699000000))196 ],197 must_not=[198 FieldCondition(key="status", match=MatchValue(value="archived"))199 ]200 ),201 limit=10202).points203 204# Shorthand filter syntax205response = client.query_points(206 collection_name="documents",207 query=query_embedding,208 query_filter={209 "must": [210 {"key": "category", "match": {"value": "tech"}},211 {"key": "price", "range": {"gte": 10, "lte": 100}}212 ]213 },214 limit=10215).points216```217 218### Batch search219 220```python221from qdrant_client.models import QueryRequest222 223# Multiple queries in one request (search_batch is replaced by query_batch_points)224responses = client.query_batch_points(225 collection_name="documents",226 requests=[227 QueryRequest(query=[0.1, ...], limit=5),228 QueryRequest(query=[0.2, ...], limit=5, filter={"must": [...]}),229 QueryRequest(query=[0.3, ...], limit=10)230 ]231)232# Each element is a QueryResponse; use .points233for resp in responses:234 for point in resp.points:235 print(point.id, point.score)236```237 238## RAG integration239 240### With sentence-transformers241 242```python243from sentence_transformers import SentenceTransformer244from qdrant_client import QdrantClient245from qdrant_client.models import VectorParams, Distance, PointStruct246 247# Initialize248encoder = SentenceTransformer("all-MiniLM-L6-v2")249client = QdrantClient(host="localhost", port=6333)250 251# Create collection252client.create_collection(253 collection_name="knowledge_base",254 vectors_config=VectorParams(size=384, distance=Distance.COSINE)255)256 257# Index documents258documents = [259 {"id": 1, "text": "Python is a programming language", "source": "wiki"},260 {"id": 2, "text": "Machine learning uses algorithms", "source": "textbook"},261]262 263points = [264 PointStruct(265 id=doc["id"],266 vector=encoder.encode(doc["text"]).tolist(),267 payload={"text": doc["text"], "source": doc["source"]}268 )269 for doc in documents270]271client.upsert(collection_name="knowledge_base", points=points)272 273# RAG retrieval274def retrieve(query: str, top_k: int = 5) -> list[dict]:275 query_vector = encoder.encode(query).tolist()276 response = client.query_points(277 collection_name="knowledge_base",278 query=query_vector,279 limit=top_k280 )281 return [{"text": r.payload["text"], "score": r.score} for r in response.points]282 283# Use in RAG pipeline284context = retrieve("What is Python?")285prompt = f"Context: {context}\n\nQuestion: What is Python?"286```287 288### With LangChain289 290```python291from langchain_community.vectorstores import Qdrant292from langchain_community.embeddings import HuggingFaceEmbeddings293 294embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")295vectorstore = Qdrant.from_documents(documents, embeddings, url="http://localhost:6333", collection_name="docs")296retriever = vectorstore.as_retriever(search_kwargs={"k": 5})297```298 299### With LlamaIndex300 301```python302from llama_index.vector_stores.qdrant import QdrantVectorStore303from llama_index.core import VectorStoreIndex, StorageContext304 305vector_store = QdrantVectorStore(client=client, collection_name="llama_docs")306storage_context = StorageContext.from_defaults(vector_store=vector_store)307index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)308query_engine = index.as_query_engine()309```310 311## Multi-vector support312 313### Named vectors (different embedding models)314 315```python316from qdrant_client.models import VectorParams, Distance317 318# Collection with multiple vector types319client.create_collection(320 collection_name="hybrid_search",321 vectors_config={322 "dense": VectorParams(size=384, distance=Distance.COSINE),323 "sparse": VectorParams(size=30000, distance=Distance.DOT)324 }325)326 327# Insert with named vectors328client.upsert(329 collection_name="hybrid_search",330 points=[331 PointStruct(332 id=1,333 vector={334 "dense": dense_embedding,335 "sparse": sparse_embedding336 },337 payload={"text": "document text"}338 )339 ]340)341 342# Search specific named vector (pass the vector name via `using`)343response = client.query_points(344 collection_name="hybrid_search",345 query=query_dense,346 using="dense", # Specify which named vector to search347 limit=10348)349results = response.points350```351 352### Sparse vectors (BM25, SPLADE)353 354```python355from qdrant_client.models import SparseVectorParams, SparseIndexParams, SparseVector356 357# Collection with sparse vectors358client.create_collection(359 collection_name="sparse_search",360 vectors_config={},361 sparse_vectors_config={"text": SparseVectorParams(index=SparseIndexParams(on_disk=False))}362)363 364# Insert sparse vector365client.upsert(366 collection_name="sparse_search",367 points=[PointStruct(id=1, vector={"text": SparseVector(indices=[1, 5, 100], values=[0.5, 0.8, 0.2])}, payload={"text": "document"})]368)369```370 371## Quantization (memory optimization)372 373```python374from qdrant_client.models import ScalarQuantization, ScalarQuantizationConfig, ScalarType375 376# Scalar quantization (4x memory reduction)377client.create_collection(378 collection_name="quantized",379 vectors_config=VectorParams(size=384, distance=Distance.COSINE),380 quantization_config=ScalarQuantization(381 scalar=ScalarQuantizationConfig(382 type=ScalarType.INT8,383 quantile=0.99, # Clip outliers384 always_ram=True # Keep quantized in RAM385 )386 )387)388 389# Search with rescoring390response = client.query_points(391 collection_name="quantized",392 query=query,393 search_params={"quantization": {"rescore": True}}, # Rescore top results394 limit=10395)396results = response.points397```398 399## Payload indexing400 401```python402from qdrant_client.models import PayloadSchemaType403 404# Create payload index for faster filtering405client.create_payload_index(406 collection_name="documents",407 field_name="category",408 field_schema=PayloadSchemaType.KEYWORD409)410 411client.create_payload_index(412 collection_name="documents",413 field_name="timestamp",414 field_schema=PayloadSchemaType.INTEGER415)416 417# Index types: KEYWORD, INTEGER, FLOAT, GEO, TEXT (full-text), BOOL418```419 420## Production deployment421 422### Qdrant Cloud423 424```python425from qdrant_client import QdrantClient426 427# Connect to Qdrant Cloud428client = QdrantClient(429 url="https://your-cluster.cloud.qdrant.io",430 api_key="your-api-key"431)432```433 434### Performance tuning435 436```python437# Optimize for search speed (higher recall)438client.update_collection(439 collection_name="documents",440 hnsw_config=HnswConfigDiff(ef_construct=200, m=32)441)442 443# Optimize for indexing speed (bulk loads)444client.update_collection(445 collection_name="documents",446 optimizer_config={"indexing_threshold": 20000}447)448```449 450## Best practices451 4521. **Batch operations** - Use batch upsert/search for efficiency4532. **Payload indexing** - Index fields used in filters4543. **Quantization** - Enable for large collections (>1M vectors)4554. **Sharding** - Use for collections >10M vectors4565. **On-disk storage** - Enable `on_disk_payload` for large payloads4576. **Connection pooling** - Reuse client instances458 459## Common issues460 461**Slow search with filters:**462```python463# Create payload index for filtered fields464client.create_payload_index(465 collection_name="docs",466 field_name="category",467 field_schema=PayloadSchemaType.KEYWORD468)469```470 471**Out of memory:**472```python473# Enable quantization and on-disk storage474client.create_collection(475 collection_name="large_collection",476 vectors_config=VectorParams(size=384, distance=Distance.COSINE),477 quantization_config=ScalarQuantization(...),478 on_disk_payload=True479)480```481 482**Connection issues:**483```python484# Use timeout and retry485client = QdrantClient(486 host="localhost",487 port=6333,488 timeout=30,489 prefer_grpc=True # gRPC for better performance490)491```492 493## References494 495- **[Advanced Usage](references/advanced-usage.md)** - Distributed mode, hybrid search, recommendations496- **[Troubleshooting](references/troubleshooting.md)** - Common issues, debugging, performance tuning497 498## Resources499 500- **GitHub**: https://github.com/qdrant/qdrant (22k+ stars)501- **Docs**: https://qdrant.tech/documentation/502- **Python Client**: https://github.com/qdrant/qdrant-client503- **Cloud**: https://cloud.qdrant.io504- **Version**: 1.14.0+505- **License**: Apache 2.0506 Discovery context
Discovered by repository scan. No exact path reference found in the snapshot’s root AGENTS.md.