Vector Database Examples: Real-World Use Cases and Code
By Marcin Piekarski builtweb.com.au · Last Updated: 11 February 2026
TL;DR: Practical examples of vector databases in action: semantic search, chatbot memory, recommendation systems, and more with code snippets.
TL;DR
Vector databases power semantic search, chatbot memory, recommendations, and duplicate detection. This guide shows real implementations: searching documents by meaning, building chatbots that remember context, finding similar products, and detecting duplicate content—with code examples you can adapt.
Why examples matter
Understanding vector databases conceptually is one thing. Seeing them in action is another. This guide walks through practical implementations you can build today.
Example 1: Semantic search for documentation
Problem: Users can't find answers in your docs because they search with different words than your documentation uses.
Solution: Convert all documentation to vectors, search by meaning instead of keywords.
How it works
- Index documents: Split docs into chunks, convert to embeddings, store in vector DB
- Search: Convert user query to embedding, find most similar chunks
- Display: Show relevant documentation sections
Code example (Python + Pinecone)
import pinecone
from openai import OpenAI
# Initialize
client = OpenAI()
pinecone.init(api_key="your-key")
index = pinecone.Index("docs")
# Index a document
def index_document(text, doc_id):
# Split into chunks (simplified)
chunks = [text[i:i+1000] for i in range(0, len(text), 1000)]
for i, chunk in enumerate(chunks):
# Create embedding
response = client.embeddings.create(
model="text-embedding-3-small",
input=chunk
)
embedding = response.data[0].embedding
# Store in Pinecone
index.upsert([(
f"{doc_id}-{i}",
embedding,
{"text": chunk, "doc_id": doc_id}
)])
# Search documents
def search_docs(query, top_k=5):
# Convert query to embedding
response = client.embeddings.create(
model="text-embedding-3-small",
input=query
)
query_embedding = response.data[0].embedding
# Search similar vectors
results = index.query(
vector=query_embedding,
top_k=top_k,
include_metadata=True
)
# Return matching text
return [match['metadata']['text'] for match in results['matches']]
# Usage
search_docs("How do I reset my password?")
# Returns relevant docs even if they say "change credentials" instead
Real companies using this:
- Notion AI searches your workspace semantically
- GitHub Copilot searches code repositories by intent
- Stripe docs use semantic search to find relevant API information
Example 2: Chatbot with conversation memory
Problem: Chatbots forget previous messages, making multi-turn conversations frustrating.
Solution: Store conversation history as vectors, retrieve relevant context for each message.
How it works
- Store messages: Each user message and AI response → embedding → vector DB
- Retrieve context: For new message, find similar past conversations
- Augment prompt: Feed relevant history to LLM with new message
Code example (Python + Chroma)
import chromadb
from openai import OpenAI
client = OpenAI()
chroma_client = chromadb.Client()
collection = chroma_client.create_collection("chat_history")
def save_message(user_id, message, role):
"""Store message in vector DB"""
collection.add(
documents=[message],
metadatas=[{"user_id": user_id, "role": role}],
ids=[f"{user_id}-{len(collection.get())}"]
)
def get_relevant_history(user_id, current_message, n=5):
"""Retrieve relevant past messages"""
results = collection.query(
query_texts=[current_message],
n_results=n,
where={"user_id": user_id}
)
return results['documents'][0]
def chat(user_id, message):
"""Chat with memory"""
# Get relevant past context
context = get_relevant_history(user_id, message)
# Build prompt with context
prompt = f"""Previous relevant conversation:
{chr(10).join(context)}
Current message: {message}
Respond naturally, referencing past conversation when relevant."""
# Get AI response
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
ai_message = response.choices[0].message.content
# Save both messages
save_message(user_id, message, "user")
save_message(user_id, ai_message, "assistant")
return ai_message
# Usage
chat("user123", "My name is Alice")
chat("user123", "What's the weather like?")
chat("user123", "What did I tell you my name was?")
# Chatbot remembers Alice even though it was mentioned earlier
Real examples:
- ChatGPT uses vector search for long-term memory features
- Customer service bots reference past support tickets
- Personal AI assistants remember user preferences
Example 3: Product recommendation system
Problem: Show users products similar to what they're viewing.
Solution: Convert product descriptions to vectors, find nearest neighbors.
How it works
- Index products: Product title + description → embedding → vector DB
- Find similar: When user views product, search for similar vectors
- Display recommendations: Show top matches
Code example (Python + Qdrant)
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
from openai import OpenAI
client = OpenAI()
qdrant = QdrantClient(":memory:") # Use actual server in production
# Create collection
qdrant.create_collection(
collection_name="products",
vectors_config=VectorParams(size=1536, distance=Distance.COSINE)
)
def index_product(product_id, name, description, price, category):
"""Add product to vector DB"""
# Create embedding from name + description
text = f"{name}. {description}"
response = client.embeddings.create(
model="text-embedding-3-small",
input=text
)
embedding = response.data[0].embedding
# Store in Qdrant
qdrant.upsert(
collection_name="products",
points=[PointStruct(
id=product_id,
vector=embedding,
payload={
"name": name,
"description": description,
"price": price,
"category": category
}
)]
)
def recommend_similar(product_id, limit=5):
"""Find similar products"""
# Get product vector
product = qdrant.retrieve(
collection_name="products",
ids=[product_id]
)[0]
# Search similar
results = qdrant.search(
collection_name="products",
query_vector=product.vector,
limit=limit + 1 # +1 because first result is the product itself
)
# Return recommendations (skip first = self)
return [
{
"name": hit.payload["name"],
"price": hit.payload["price"],
"similarity": hit.score
}
for hit in results[1:]
]
# Usage
index_product(1, "Blue Running Shoes", "Lightweight athletic shoes for daily training", 79.99, "footwear")
index_product(2, "Trail Running Sneakers", "Durable shoes for off-road running", 99.99, "footwear")
index_product(3, "Yoga Mat", "Non-slip exercise mat", 29.99, "fitness")
recommend_similar(1)
# Returns trail running sneakers (similar product) but not yoga mat
Real examples:
- Amazon's "Customers who bought this also bought"
- Spotify's song recommendations
- Netflix's movie suggestions
Example 4: Duplicate content detection
Problem: Users submit duplicate support tickets or questions already answered.
Solution: Check if incoming content is similar to existing entries.
How it works
- Index existing content: All past tickets/questions → embeddings
- Check new content: Convert to embedding, search for high similarity matches
- Suggest duplicates: If similarity > threshold, show user existing content
Code example (Python + pgvector)
import psycopg2
from pgvector.psycopg2 import register_vector
from openai import OpenAI
client = OpenAI()
conn = psycopg2.connect(database="support_db")
register_vector(conn)
# Setup (run once)
def setup_database():
cur = conn.cursor()
cur.execute('CREATE EXTENSION IF NOT EXISTS vector')
cur.execute('''
CREATE TABLE IF NOT EXISTS tickets (
id SERIAL PRIMARY KEY,
content TEXT,
embedding vector(1536),
status TEXT
)
''')
conn.commit()
def add_ticket(content):
"""Add new support ticket"""
# Create embedding
response = client.embeddings.create(
model="text-embedding-3-small",
input=content
)
embedding = response.data[0].embedding
# Check for duplicates first
duplicates = find_similar_tickets(embedding)
if duplicates:
return {
"duplicate": True,
"similar_tickets": duplicates
}
# Not a duplicate, add ticket
cur = conn.cursor()
cur.execute(
'INSERT INTO tickets (content, embedding, status) VALUES (%s, %s, %s)',
(content, embedding, 'open')
)
conn.commit()
return {"duplicate": False, "ticket_id": cur.lastrowid}
def find_similar_tickets(embedding, threshold=0.85):
"""Find tickets with similarity above threshold"""
cur = conn.cursor()
cur.execute('''
SELECT id, content, 1 - (embedding <=> %s) AS similarity
FROM tickets
WHERE 1 - (embedding <=> %s) > %s
ORDER BY similarity DESC
LIMIT 5
''', (embedding, embedding, threshold))
return [
{"id": row[0], "content": row[1], "similarity": row[2]}
for row in cur.fetchall()
]
# Usage
add_ticket("I can't log in to my account")
add_ticket("Unable to access my account login") # Detected as duplicate!
Real examples:
- Stack Overflow suggests similar questions while you type
- GitHub detects duplicate issues
- Zendesk flags similar support tickets
Example 5: Multi-modal search (text + images)
Problem: Search images using text descriptions.
Solution: Use multi-modal embeddings (like CLIP) to search images by semantic meaning.
Simplified example
from openai import OpenAI
import pinecone
client = OpenAI()
pinecone.init(api_key="your-key")
index = pinecone.Index("images")
def index_image(image_url, caption, image_id):
"""Index image with its caption"""
# Use caption as embedding (simplified)
# In production, use CLIP or similar multi-modal model
response = client.embeddings.create(
model="text-embedding-3-small",
input=caption
)
embedding = response.data[0].embedding
index.upsert([(
image_id,
embedding,
{"image_url": image_url, "caption": caption}
)])
def search_images(text_query, top_k=10):
"""Search images using text"""
response = client.embeddings.create(
model="text-embedding-3-small",
input=text_query
)
query_embedding = response.data[0].embedding
results = index.query(
vector=query_embedding,
top_k=top_k,
include_metadata=True
)
return [match['metadata'] for match in results['matches']]
# Usage
search_images("sunset over mountains")
# Returns images matching that description, even if captions use different words
Real examples:
- Google Photos search ("show me pictures of dogs")
- Pinterest visual search
- Shopify product image search
Choosing the right vector database
Based on these examples, here's what to use:
Pinecone: Easiest for prototypes and MVPs, fully managed
Chroma: Best for local development and small-scale apps
Qdrant: Great for production, excellent filtering and performance
pgvector: Use if you already have PostgreSQL
Weaviate: Best for hybrid search (keywords + vectors)
Performance tips
From real implementations:
Chunking matters: Test different chunk sizes (256, 512, 1024 tokens) for your use case
Metadata filtering: Filter by category/date first, then vector search within results
Batch operations: Insert/update in batches of 100-1000, not one-by-one
Cache embeddings: Don't re-embed the same content repeatedly
Monitor recall: Measure whether you're actually finding the right results
What to try next
Pick one example and implement it:
- Start with the semantic search example (simplest)
- Use a free vector DB tier (Pinecone, Chroma)
- Index 50-100 items to test
- Measure search quality
- Iterate on chunking and retrieval
Related reading:
- Vector Databases 101 — Conceptual deep dive
- Embeddings Explained — How vectors work
- RAG Systems — Building retrieval-augmented generation
Frequently Asked Questions
Which vector database should I start with?
Chroma is best for local prototyping since it runs in-memory with zero setup. For production, Pinecone is the easiest managed option. If you already use PostgreSQL, pgvector adds vector capabilities without a new service.
How many vectors can a vector database handle?
It depends on the database. Pinecone and Milvus handle billions of vectors. Chroma works well for hundreds of thousands. pgvector is comfortable with millions. Start small and scale as your needs grow.
Do I need to re-embed my data if I change embedding models?
Yes. Different embedding models produce vectors of different dimensions and meanings. If you switch from one model to another, you need to re-embed all your data and rebuild your index. Plan for this when choosing your initial model.
How do I know if my vector search results are good enough?
Create a test set of queries with known correct results. Measure recall (did you find the right items?) and precision (are the results relevant?). Aim for 90%+ recall. If results are poor, experiment with chunk sizes, embedding models, and distance metrics.
Was this guide helpful?
Your feedback helps us improve our guides
About the Authors
Marcin Piekarski· Frontend Lead & AI Educator
Marcin is a Frontend Lead with 20+ years in tech. Currently building headless ecommerce at Harvey Norman (Next.js, Node.js, GraphQL). He created Field Guide to AI to help others understand AI tools practically—without the jargon.
Credentials & Experience:
- 20+ years web development experience
- Frontend Lead at Harvey Norman (10 years)
- Worked with: Gumtree, CommBank, Woolworths, Optus, M&C Saatchi
- Runs AI workshops for teams
- Founder of builtweb.com.au
- Daily AI tools user: ChatGPT, Claude, Gemini, AI coding assistants
- Specializes in React ecosystem: React, Next.js, Node.js
Areas of Expertise:
Prism AI· AI Research & Writing Assistant
Prism AI is the AI ghostwriter behind Field Guide to AI—a collaborative ensemble of frontier models (Claude, ChatGPT, Gemini, and others) that assist with research, drafting, and content synthesis. Like light through a prism, human expertise is refracted through multiple AI perspectives to create clear, comprehensive guides. All AI-generated content is reviewed, fact-checked, and refined by Marcin before publication.
Transparency Note: All AI-assisted content is thoroughly reviewed, fact-checked, and refined by Marcin Piekarski before publication.
Key Terms Used in This Guide
Vector Database
A specialized database designed to store and search embeddings—numerical representations of text, images, or other data. It finds similar items by comparing how close their vectors are in mathematical space.
Embedding
A list of numbers that represents the meaning of text, images, or other data. Similar meanings produce similar numbers, so computers can measure how 'close' two concepts are.
RAG (Retrieval-Augmented Generation)
A technique where AI searches your documents for relevant information first, then uses what it finds to generate accurate, grounded answers.
Related Guides
Vector Databases 101: Storage, Indexing, and Search
IntermediateDeep dive into vector databases. How they work, when to use them, and how to choose the right one for your needs.
11 min readEmbeddings & RAG Explained (Plain English)
IntermediateHow AI tools search and retrieve information from documents. Understand embeddings and Retrieval-Augmented Generation without the math.
11 min readEvaluating AI Answers (Hallucinations, Checks, and Evidence)
IntermediateHow to spot when AI gets it wrong. Practical techniques to verify accuracy, detect hallucinations, and build trust in AI outputs.
10 min read