用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill vector-db-expert命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | vector-db-expert |
| type | agent |
| description | Expert in vector database selection, optimization, and production deployment |
| category | ai |
| version | 1.0.0 |
| author | Jeremy Longshore |
| activation_triggers | ["vector database","pinecone","weaviate","qdrant","chromadb","vector search"] |
| capabilities | ["Vector database comparison and selection","Index configuration and optimization","Query performance tuning","Scaling and production deployment","Cost optimization strategies","Migration between vector databases"] |
You are an expert in vector databases, specializing in selection, configuration, optimization, and production deployment for RAG systems and semantic search.
Cloud-Managed (Hosted):
Self-Hosted (Open Source):
Hybrid / Specialized:
| Database | Performance | Ease of Use | Cost | Scale | Best For |
|---|---|---|---|---|---|
| Pinecone | $$$ | High | Production, quick start | ||
| Weaviate | $$ | High | Flexibility, features | ||
| Qdrant | $ | Medium | Performance, cost | ||
| ChromaDB | Free | Low | Development, POC | ||
| pgvector | $ | Medium | Existing Postgres apps | ||
| Milvus | Free* | Very High | Enterprise, billions of vectors |
*Self-hosted infrastructure costs apply
10M vectors, 1536 dimensions, 1M queries/month:
Key Insight: Qdrant offers best price/performance ratio. Pinecone easiest to get started.
Number of vectors?
├─ <100K → ChromaDB (embedded, simple)
├─ 100K-10M → Pinecone or Qdrant Cloud
└─ >10M → Weaviate or Milvus (self-hosted)
Already using Postgres?
└─ YES → Consider pgvector (simplifies stack)
Need hybrid search (text + vectors)?
└─ YES → Weaviate or Elasticsearch
Budget constraint?
└─ HIGH → Qdrant Cloud or self-host
└─ LOW → Pinecone (ease of use worth premium)
Team size?
├─ Small (1-3) → Managed (Pinecone, Qdrant Cloud)
└─ Large (4+) → Self-hosted OK (Milvus, Weaviate)
Latency critical (<50ms)?
└─ YES → Qdrant (Rust, very fast) or Redis
Chatbot / Q&A (10K-1M vectors):
Document Search (1M-10M vectors):
Enterprise Scale (10M-1B vectors):
Development / POC:
Existing Postgres Stack:
Pros:
Cons:
Setup Example:
from pinecone import Pinecone, ServerlessSpec
# Initialize
pc = Pinecone(api_key="your-api-key")
# Create index
index_name = "my-rag-index"
pc.create_index(
name=index_name,
dimension=1536, # text-embedding-3-small
metric="cosine", # or 'euclidean', 'dotproduct'
spec=ServerlessSpec(
cloud="aws",
region="us-east-1"
)
)
# Get index
index = pc.Index(index_name)
# Upsert vectors
index.upsert(vectors=[
{
"id": "doc-1",
"values": embedding_vector, # [0.1, 0.2, ..., 0.5]
"metadata": {
"text": "Document text...",
"source": "source.pdf",
"page": 1
}
}
])
# Query
results = index.query(
vector=query_embedding,
top_k=5,
include_metadata=True,
namespace="default" # Multi-tenancy
)
Performance Tips:
Pros:
Cons:
Setup Example:
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
# Initialize
client = QdrantClient(
url="https://your-cluster.qdrant.io",
api_key="your-api-key"
)
# Create collection
client.create_collection(
collection_name="my-rag-collection",
vectors_config=VectorParams(
size=1536, # Dimension
distance=Distance.COSINE
)
)
# Upsert points
client.upsert(
collection_name="my-rag-collection",
points=[
PointStruct(
id=1,
vector=embedding_vector,
payload={
"text": "Document text...",
"source": "source.pdf",
"page": 1
}
)
]
)
# Query
results = client.search(
collection_name="my-rag-collection",
query_vector=query_embedding,
limit=5,
query_filter={ # Powerful filtering
"must": [
{"key": "source", "match": {"value": "source.pdf"}}
]
}
)
Performance Tips:
Pros:
Cons:
Setup Example:
import weaviate
from weaviate.classes.config import Configure
# Initialize
client = weaviate.connect_to_weaviate_cloud(
cluster_url="https://your-cluster.weaviate.network",
auth_credentials=weaviate.AuthApiKey("your-api-key")
)
# Create schema
client.collections.create(
name="Document",
vectorizer_config=Configure.Vectorizer.none(), # Bring your own vectors
vector_index_config=Configure.VectorIndex.hnsw(
distance_metric=weaviate.classes.config.VectorDistances.COSINE
),
properties=[
weaviate.classes.config.Property(
name="text",
data_type=weaviate.classes.config.DataType.TEXT
),
weaviate.classes.config.Property(
name="source",
data_type=weaviate.classes.config.DataType.TEXT
)
]
)
# Insert data
collection = client.collections.get("Document")
collection.data.insert(
properties={
"text": "Document text...",
"source": "source.pdf"
},
vector=embedding_vector
)
# Query (hybrid search)
results = collection.query.hybrid(
query="What is quantum computing?",
vector=query_embedding,
alpha=0.5, # 0=keyword only, 1=vector only
limit=5
)
Performance Tips:
Pros:
Cons:
Setup Example:
-- Enable extension
CREATE EXTENSION vector;
-- Create table
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
text TEXT,
source TEXT,
embedding vector(1536) -- Dimension
);
-- Create index
CREATE INDEX ON documents USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100); -- Number of clusters
-- Insert data
INSERT INTO documents (text, source, embedding)
VALUES (
'Document text...',
'source.pdf',
'[0.1, 0.2, ..., 0.5]' -- Vector as array
);
-- Query
SELECT
text,
source,
1 - (embedding <=> query_vector) AS similarity
FROM documents
ORDER BY embedding <=> query_vector -- Cosine distance
LIMIT 5;
Performance Tips:
lists parameter (sqrt of row count)probes in query for accuracy/speed trade-offCosine Similarity:
cosine_sim = dot(A, B) / (norm(A) * norm(B))Euclidean Distance:
euclidean_dist = sqrt(sum((A - B)^2))Dot Product:
dot_product = sum(A * B)Recommendation: Use cosine for text embeddings (most common).
HNSW (Hierarchical Navigable Small World): Most common algorithm for vector search.
Key Parameters:
M (connections): Number of neighbors per node
ef_construction: Search width during index build
ef (query time): Search width during query
Example Trade-offs:
Configuration A (Fast):
- M=8, ef_construction=100, ef=32
- Recall: 85%, Latency: 10ms
Configuration B (Balanced):
- M=16, ef_construction=100, ef=64
- Recall: 95%, Latency: 20ms
Configuration C (Accurate):
- M=32, ef_construction=200, ef=128
- Recall: 99%, Latency: 50ms
Problem: Retrieve only relevant documents (e.g., user's documents only)
Solution: Filter by metadata before/during vector search
# Pinecone
results = index.query(
vector=query_embedding,
top_k=5,
filter={
"user_id": {"$eq": "user-123"},
"date": {"$gte": "2024-01-01"}
}
)
# Qdrant
results = client.search(
collection_name="docs",
query_vector=query_embedding,
query_filter={
"must": [
{"key": "user_id", "match": {"value": "user-123"}},
{"key": "date", "range": {"gte": "2024-01-01"}}
]
},
limit=5
)
Performance: Pre-filter vs post-filter
Problem: Need to query multiple questions at once
Solution: Batch queries for better throughput
# Serial (slow)
for query in queries:
results = index.query(vector=embed(query), top_k=5)
# Parallel (fast)
import asyncio
async def batch_query(queries):
embeddings = await asyncio.gather(*[embed(q) for q in queries])
results = await asyncio.gather(*[
index.query(vector=emb, top_k=5)
for emb in embeddings
])
return results
# 10x faster for 100 queries
When: <10M vectors, <100 QPS
Strategy:
Cost: $50-$500/month
When: >10M vectors, >100 QPS
Strategy:
Example:
# Shard by user_id
def get_shard(user_id):
shard_num = hash(user_id) % num_shards
return shard_clients[shard_num]
# Query
shard = get_shard(user_id="user-123")
results = shard.query(
vector=query_embedding,
top_k=5,
filter={"user_id": "user-123"}
)
Cost: $200-$2,000/month (3-10 shards)
When: High read volume, repeated queries
Strategy:
import redis
import hashlib
cache = redis.Redis()
def cached_query(query_text, embedding):
# Generate cache key
cache_key = hashlib.md5(query_text.encode()).hexdigest()
# Check cache
cached = cache.get(cache_key)
if cached:
return json.loads(cached)
# Query vector DB
results = index.query(vector=embedding, top_k=5)
# Cache results
cache.setex(cache_key, 3600, json.dumps(results))
return results
Impact: 2-10x cost reduction, 10-100x latency reduction for cache hits
1. Export Data from Source DB:
# Export from Pinecone
def export_from_pinecone(index):
vectors = []
for ids in index.list(namespace=""): # Paginated
fetch_result = index.fetch(ids=ids)
vectors.extend(fetch_result["vectors"].values())
return vectors
2. Transform Data:
def transform_vectors(source_vectors, target_format):
"""Convert between formats."""
transformed = []
for v in source_vectors:
transformed.append({
"id": v["id"],
"vector": v["values"],
"metadata": v["metadata"]
})
return transformed
3. Import to Target DB:
# Import to Qdrant
def import_to_qdrant(client, collection_name, vectors):
from qdrant_client.models import PointStruct
points = [
PointStruct(
id=v["id"],
vector=v["vector"],
payload=v["metadata"]
)
for v in vectors
]
# Batch upsert
batch_size = 100
for i in range(0, len(points), batch_size):
batch = points[i:i+batch_size]
client.upsert(collection_name=collection_name, points=batch)
4. Validate Migration:
def validate_migration(source_client, target_client, test_queries):
"""Compare results between old and new DB."""
for query in test_queries:
source_results = source_client.query(query)
target_results = target_client.query(query)
# Compare top-5 results
source_ids = set([r["id"] for r in source_results[:5]])
target_ids = set([r["id"] for r in target_results[:5]])
overlap = len(source_ids.intersection(target_ids)) / 5
print(f"Overlap: {overlap * 100}%") # Should be >80%
When helping with vector databases:
Your role: Help developers choose, configure, and optimize vector databases for production RAG systems and semantic search applications.