Vector Databases & Similarity Search Cheatsheet
Core operations, index creation, HNSW tuning, metadata filtering, and client syntax for Pinecone, Qdrant, Milvus, and Chroma.
Interactive Skill Mastery
Mark commands as learned to build your customized reference tracker. Retained locally in this browser.
Pinecone
When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
pc.create_index(name='index', dimension=1536, metric='cosine', spec=ServerlessSpec(cloud='aws', region='us-east-1'))Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
index.upsert(vectors=[('id-1', [0.1, 0.2, ...], {'genre': 'comedy'})], namespace='ns1')Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
index.query(vector=[0.1, 0.2, ...], top_k=5, filter={'genre': 'comedy'}, include_metadata=True)Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
index.describe_index_stats()Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.Qdrant
When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
client.create_collection(collection_name='col', vectors_config=VectorParams(size=1536, distance=Distance.COSINE))Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
client.search(collection_name='col', query_vector=[0.1, ...], query_filter=Filter(must=[FieldCondition(key='genre', match=MatchValue(value='comedy'))]), limit=5)Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
client.upsert(collection_name='col', points=[PointStruct(id=1, vector=[0.1, ...], payload={'role': 'user'})])Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.Milvus
When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
connections.connect(alias='default', host='localhost', port='19530')Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
schema.add_field(field_name='vector', datatype=DataType.FLOAT_VECTOR, dim=1536)Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
index_params.add_index(field_name='vector', index_type='HNSW', metric_type='COSINE', params={'M': 16, 'efConstruction': 200})Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.Chroma DB
When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
collection = chroma_client.get_or_create_collection(name='col', embedding_function=openai_ef)Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
collection.query(query_embeddings=[[0.1, ...]], n_results=5, where={'genre': 'comedy'})Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
chroma_client.heartbeat()Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.Indexing & Metrics
When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
Distance Formulas: Cosine: 1 - (A · B) / (||A|| ||B||) | L2 (Euclidean): ||A - B||^2 | Dot Product: A · BOutput Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
HNSW Tuning: M (outgoing links: 4-64) | efConstruction (build speed/depth: 100-500) | efSearch (query search depth: 16-128)Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
IVF_FLAT Indexing: nlist (number of clusters: 256-65536) | nprobe (search cluster depth: 1-512)Output Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.When to Use
When storing, indexing, or conducting high-performance nearest-neighbor search query sweeps on multi-dimensional floating point embeddings.
Common Mistakes
Failing to normalize vector coordinate arrays before running Dot Product metric queries, causing wild and inaccurate proximity scores.
Shortcut / Pro-Tip
Build indexes with Hierarchical Navigable Small World (HNSW) graphs and configure high efSearch parameters to maximize search recall.Example
Scalar Quantization (SQ8): Reduces 32-bit floats to 8-bit integersOutput Example
High-dimensional spatial search index compiled and queried. Proximity distances and matched vectors retrieved.Vector Databases Best Practices
1Select Distance Metrics carefully
Align your database distance calculations with your embedding models. Use Cosine Similarity for normalized vectors, Dot Product for maximum performance, and L2 (Euclidean) for clustering applications.
2Build Indexes with HNSW Graphs
For low-latency, high-QPS applications, index collections using Hierarchical Navigable Small World (HNSW) graphs. Adjust efConstruction and M to fine-tune index build speed vs. search recall.
3Optimize with Pre-Filtering Constraints
Configure metadata schemas and indexes to execute metadata filters *before* the vector search calculation (pre-filtering), avoiding precision loss and random walks.
4Partition Collections using Namespaces
Establish isolated namespaces or partitions within a single index to separate multi-tenant data, preventing cross-tenant document leakage.
5Monitor Vector Dimension sizes
Match index configurations exactly to your generator models (e.g. 1536 for OpenAI text-embedding-3-small, 3072 for text-embedding-3-large) to prevent dimensional mismatches on upsert.
Common Vector Databases Errors & Solutions
Dimensional mismatch exception on vector upsert
Verify that the dimension parameter defined during index creation matches your embedding model output (e.g., Ada-002 outputting 1536, Cohere v3 outputting 1024).
Slow query execution times (high latency) under peak load
The index is likely running out of RAM or searching too deep. Lower your efSearch search parameter, scale up database memory allocations, or switch to Quantized vector storage.
Post-filtering returning zero results on metadata queries
Filtering *after* vector search (post-filtering) discards matched nearest neighbors that fail metadata checks. Switch to strict database-level 'pre-filtering' to search only valid records.
Memory consumption skyrocketing on HNSW indexes
HNSW stores full graph links in memory. Reduce the graph connectivity parameter 'M' (e.g., to 12 or 16) or apply Scalar Quantization (SQ) or Product Quantization (PQ) to compress vectors.
Inaccurate distance scores on dot product calculations
Dot product only matches cosine similarity if vector coordinates are normalized. Ensure all input vectors are L2-normalized on generation, or switch the database metric to Cosine.
Common Vector Databases Interview Questions
Q1How does Hierarchical Navigable Small World (HNSW) enable sub-linear vector search?
HNSW is a graph-based indexing algorithm that creates a multi-layered skip-list of vectors. Upper layers contain long-range connections for fast, coarse spatial jumps, while lower layers contain dense, short-range connections for granular navigation. Search traverses top-down, finding the local neighborhood in logarithmic time.
Q2What is Product Quantization (PQ) and how does it save memory?
Product Quantization is a compression technique that splits high-dimensional vectors into smaller sub-vectors, runs K-means clustering on these sub-vectors to define centroids, and replaces each sub-vector with a short 1-byte centroid ID index. This can reduce memory footprint by 95% at the cost of minor recall accuracy loss.
Q3Explain the difference between Pre-Filtering, Post-Filtering, and Single-Stage Filtering in Vector Search.
Post-Filtering searches vectors first and discards results that do not match metadata, often returning fewer results than requested. Pre-Filtering filters records by metadata first and searches vectors only among matched rows, which is slow if matches are huge. Single-Stage (Iterative) Filtering traverses the index graph while actively checking metadata on every node, balancing speed and accuracy.
Q4Why is Cosine Similarity identical to Dot Product for normalized vectors?
Cosine similarity is mathematically defined as the dot product of two vectors divided by the product of their magnitudes: (A · B) / (||A|| ||B||). If vectors are L2-normalized, their magnitudes are exactly 1, reducing the formula to a simple dot product (A · B), which bypasses expensive square root divisions.
Q5What are the trade-offs between Flat (Brute-Force) Indexing and Approximate Nearest Neighbor (ANN) Indexing?
Flat Indexing computes exact distances against every vector in the database, ensuring 100% recall accuracy but scaling linearly O(N), which is too slow for large datasets. ANN indexing (using HNSW, IVF, or ScaNN) trades minor recall accuracy (typically 95-99%) for constant or logarithmic search latency O(log N), making it highly scalable.
Related Resources
REST API Tester
Test API routes and endpoints directly in your browser with full request controls.
JSON Formatter & Validator
Beautify, validate, and minify JSON structures instantly.
Best Free Online Developer Tools
An expert review of must-have online utilities for developers.
Git Cheatsheet
Essential command reference for local and remote version control repositories.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com