skills/vector-db/SKILL.md
Vector databases for embeddings, semantic search, and RAG pipelines. Use when user mentions "vector database", "embeddings", "semantic search", "RAG", "retrieval augmented generation", "pinecone", "chromadb", "pgvector", "qdrant", "weaviate", "similarity search", "embedding store", or building AI search features.
npx skillsauth add 1mangesh1/dev-skills-collection vector-dbInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Vector databases store high-dimensional numerical representations (embeddings) and enable fast similarity search. Unlike traditional databases that match exact values, vector databases find the closest vectors to a query vector, enabling semantic matching.
Core capabilities:
An embedding is a fixed-length array of floats capturing semantic meaning. Text with similar meaning produces vectors that are close together in the embedding space.
from openai import OpenAI
client = OpenAI()
response = client.embeddings.create(
input="What is a vector database?",
model="text-embedding-3-small" # 1536 dimensions
)
vector = response.data[0].embedding
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2") # 384 dimensions
vectors = model.encode(["What is a vector database?", "How does search work?"])
import cohere
co = cohere.Client("your-api-key")
response = co.embed(
texts=["What is a vector database?"],
model="embed-english-v3.0",
input_type="search_document" # Use "search_query" for queries
)
vector = response.embeddings[0]
Lightweight, embedded vector database. Good for prototyping and small-to-medium workloads.
pip install chromadb
import chromadb
client = chromadb.Client() # In-memory
# client = chromadb.PersistentClient(path="./chroma_data") # Persistent
collection = client.create_collection(
name="documents",
metadata={"hnsw:space": "cosine"} # cosine, l2, or ip
)
# Add documents (ChromaDB auto-generates embeddings with its default model)
collection.add(
ids=["doc1", "doc2", "doc3"],
documents=[
"Vector databases store embeddings",
"PostgreSQL is a relational database",
"Semantic search finds similar meaning"
],
metadatas=[
{"source": "wiki", "topic": "vectors"},
{"source": "docs", "topic": "sql"},
{"source": "wiki", "topic": "search"}
]
)
# Query
results = collection.query(
query_texts=["How do vector stores work?"],
n_results=2,
where={"source": "wiki"} # Optional metadata filter
)
# results["documents"], results["distances"], results["metadatas"]
To use pre-computed embeddings, pass embeddings=[[...]] instead of documents in both add() and query() (via query_embeddings).
Adds vector column type and similarity operators to PostgreSQL. Use when you already run Postgres and want vectors alongside relational data.
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
embedding vector(1536),
metadata JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- HNSW index (recommended)
CREATE INDEX ON documents
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
-- IVFFlat index (faster to build, slower to query)
CREATE INDEX ON documents
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
Operator classes: vector_cosine_ops (<=>), vector_l2_ops (<->), vector_ip_ops (<#>).
SELECT id, content, 1 - (embedding <=> $1::vector) AS similarity
FROM documents
WHERE metadata->>'category' = 'technical'
ORDER BY embedding <=> $1::vector
LIMIT 5;
Python: use psycopg with pgvector.psycopg.register_vector(conn) to pass vectors directly as parameters.
Fully managed vector database. No infrastructure to maintain. Supports namespaces for logical partitioning.
pip install pinecone
from pinecone import Pinecone
pc = Pinecone(api_key="your-api-key")
pc.create_index(
name="my-index",
dimension=1536,
metric="cosine", # cosine, euclidean, dotproduct
spec={"serverless": {"cloud": "aws", "region": "us-east-1"}}
)
index = pc.Index("my-index")
# Upsert vectors
index.upsert(
vectors=[
{"id": "doc1", "values": [0.1, 0.2, ...],
"metadata": {"source": "wiki", "topic": "databases"}},
{"id": "doc2", "values": [0.3, 0.4, ...],
"metadata": {"source": "blog", "topic": "search"}}
],
namespace="articles"
)
# Query with metadata filter
results = index.query(
vector=[0.1, 0.2, ...],
top_k=5,
namespace="articles",
filter={"topic": {"$eq": "databases"}},
include_metadata=True
)
Namespaces partition data within an index. Queries only search within one namespace. Use them to separate tenants, environments, or document types.
High-performance vector database written in Rust. Self-hosted via Docker or managed cloud.
docker run -p 6333:6333 qdrant/qdrant
pip install qdrant-client
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="documents",
vectors_config=VectorParams(size=1536, distance=Distance.COSINE)
)
client.upsert(
collection_name="documents",
points=[
PointStruct(id=1, vector=[0.1, 0.2, ...],
payload={"text": "Vector databases store embeddings", "source": "wiki"}),
PointStruct(id=2, vector=[0.3, 0.4, ...],
payload={"text": "SQL databases use tables", "source": "docs"})
]
)
results = client.query_points(
collection_name="documents",
query=[0.1, 0.2, ...],
limit=5,
query_filter={"must": [{"key": "source", "match": {"value": "wiki"}}]}
)
| Metric | Range | Best For | Notes | |---|---|---|---| | Cosine | 0 to 1 (distance) | Text similarity | Direction matters, magnitude ignored. Most common default. | | Euclidean (L2) | 0 to infinity | Image features, spatial data | Sensitive to magnitude. | | Dot Product | -inf to inf | Pre-normalized vectors | Fastest. Equivalent to cosine for unit vectors. |
Flat (Brute Force): Compares query against every vector. Perfect recall, slowest. Use for under 10k vectors.
HNSW (Hierarchical Navigable Small World): Graph-based approximate search. High recall (>95%), fast queries, higher memory. Best general-purpose index. Key params: M (connections per node), ef_construction (build quality), ef (search quality).
IVF (Inverted File Index): Clusters vectors, searches nearby clusters only. Faster to build than HNSW, lower recall. Key param: nlist (number of clusters). Good when you need fast index builds.
Before embedding, long documents must be split into chunks.
Fixed-Size: Split into N-token chunks with overlap. Simple and predictable.
def fixed_chunks(text, size=512, overlap=50):
words = text.split()
return [" ".join(words[i:i+size]) for i in range(0, len(words), size - overlap)]
Sentence-Based: Split on sentence boundaries using nltk.sent_tokenize(). Preserves grammatical units.
Recursive Character Splitting: Split by paragraphs, then sentences, then words. Keeps semantically related text together. Used by LangChain's RecursiveCharacterTextSplitter.
Semantic Chunking: Group sentences by embedding similarity. Start a new chunk when similarity drops below threshold. Most coherent results, but slower and more expensive.
Guidelines:
All major vector databases support combining vector similarity with metadata filters.
Common operations:
{"category": "technical"}{"date": {"$gte": "2024-01-01"}}{"tags": {"$in": ["python", "rust"]}}{"$and": [...]}, {"$or": [...]}Pre-filtering reduces the number of vectors compared and improves query speed.
Retrieval-Augmented Generation: embed query -> vector search -> inject context -> LLM generates answer.
def rag_query(question, collection, llm_client, embed_model, top_k=5):
query_vector = embed_model.encode(question).tolist()
results = collection.query(query_embeddings=[query_vector], n_results=top_k)
context = "\n\n".join(results["documents"][0])
response = llm_client.chat.completions.create(
model="claude-sonnet-4-20250514",
messages=[
{"role": "system", "content":
"Answer using only the provided context. "
"If the context lacks the answer, say so."},
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"}
]
)
return response.choices[0].message.content
Key points:
Document Q&A: Chunk documents (256-512 tokens with overlap), embed and store with metadata (doc ID, page, section), retrieve top-k at query time, pass to LLM.
Code Search: Parse into functions/classes, embed both code and natural language descriptions, use metadata filters for language/repo/path.
Recommendation Engine: Embed items by description/features, embed user preferences or recent interactions, search for similar items filtering out already-seen content.
| Need | Recommendation | |---|---| | Prototyping, local dev | ChromaDB | | Already using PostgreSQL | pgvector | | Managed, zero-ops | Pinecone | | Self-hosted, high performance | Qdrant | | Large-scale production | Qdrant or Pinecone | | Tight budget, moderate scale | pgvector or ChromaDB with persistent storage |
tools
Parallel execution with xargs, GNU parallel, and batch processing patterns. Use when user mentions "xargs", "parallel", "batch processing", "run in parallel", "parallel execution", "process list of files", "bulk operations", "concurrent commands", "map over files", or running commands on multiple inputs.
development
WebSocket implementation for real-time bidirectional communication. Use when user mentions "websocket", "ws://", "wss://", "real-time", "live updates", "chat application", "socket.io", "Server-Sent Events", "SSE", "push notifications", "live data", "streaming data", "bidirectional communication", "websocket server", "reconnection", or building real-time features.
tools
Frontend bundler configuration for Webpack and Vite. Use when user mentions "webpack", "vite", "bundler", "vite config", "webpack config", "code splitting", "tree shaking", "hot module replacement", "HMR", "build optimization", "bundle size", "chunk splitting", "loader", "plugin", "esbuild", "rollup", "dev server", or configuring JavaScript build tools.
tools
VS Code configuration, extensions, keybindings, and workspace optimization. Use when user mentions "vscode", "vs code", "vscode settings", "vscode extensions", "keybindings", "code editor", "workspace settings", "settings.json", "launch.json", "tasks.json", "vscode snippets", "devcontainer", "remote development", or customizing their VS Code setup.