惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
Martin Fowler
Martin Fowler
H
Help Net Security
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 最新话题
S
Schneier on Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
AI
AI
The Hacker News
The Hacker News
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
SecWiki News
SecWiki News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
J
Java Code Geeks
V2EX - 技术
V2EX - 技术
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
Attack and Defense Labs
Attack and Defense Labs
Security Latest
Security Latest
Help Net Security
Help Net Security
博客园 - Franky
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
Cloudbric
Cloudbric
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 【当耐特】
Schneier on Security
Schneier on Security
Google Online Security Blog
Google Online Security Blog
C
Cisco Blogs
Webroot Blog
Webroot Blog
C
CERT Recently Published Vulnerability Notes
Simon Willison's Weblog
Simon Willison's Weblog
A
Arctic Wolf
O
OpenAI News
T
Threat Research - Cisco Blogs
Know Your Adversary
Know Your Adversary
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Last Watchdog
The Last Watchdog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
85. Embeddings and Vector Search: Memory for Language Models
Akhilesh · 2026-05-16 · via DEV Community

A language model has no memory.

You ask it a question. It generates an answer from its pretrained weights. Those weights encode general knowledge learned from training data that was frozen months ago.

Your company's internal documentation? Not in there. Yesterday's news? Not in there. The specific customer complaint from last Tuesday? Definitely not in there.

The model cannot retrieve facts it was not trained on. Without retrieval, you are limited to what the model memorized during pretraining.

Vector search solves this. Convert your documents to dense vectors. Store them in a vector database. When a question comes in, convert it to a vector. Find the most similar document vectors. Give those documents to the language model as context.

Now the model can answer questions about your specific knowledge base. It retrieves relevant information at query time, not at training time.


What Embeddings Are (Revisited With Production Focus)

import torch
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")

np.random.seed(42)

print("Embedding: a dense vector representation of text.")
print()
print("Input:  any text string (word, sentence, paragraph, document)")
print("Output: a fixed-size vector of floats (e.g., 384 or 768 dimensions)")
print()
print("Key property: similar meaning → similar vector")
print("              distance in vector space = semantic distance")
print()

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("all-MiniLM-L6-v2")

sentences = [
    "Machine learning is a subset of AI.",
    "Deep learning uses neural networks.",
    "The weather is sunny today.",
    "Artificial intelligence learns from data.",
    "It is raining cats and dogs.",
]

embeddings = model.encode(sentences)
print(f"Embedding model: all-MiniLM-L6-v2")
print(f"Input sentences: {len(sentences)}")
print(f"Embedding shape: {embeddings.shape}  (5 sentences × 384 dimensions)")
print()

sim_matrix = cosine_similarity(embeddings)
print("Cosine similarity matrix:")
for i, s1 in enumerate(sentences):
    for j, s2 in enumerate(sentences):
        if i < j:
            sim = sim_matrix[i, j]
            note = " ← similar!" if sim > 0.7 else ""
            print(f"  {sim:.3f}  '{s1[:35]}''{s2[:35]}'{note}")

Enter fullscreen mode Exit fullscreen mode

Output:

Cosine similarity matrix:
  0.821  'Machine learning is a subset of AI.' ↔ 'Artificial intelligence learns from data.' ← similar!
  0.743  'Machine learning is a subset of AI.' ↔ 'Deep learning uses neural networks.' ← similar!
  0.231  'Machine learning is a subset of AI.' ↔ 'The weather is sunny today.'
  0.189  'Machine learning is a subset of AI.' ↔ 'It is raining cats and dogs.'

Enter fullscreen mode Exit fullscreen mode


Building a Semantic Search System

corpus = [
    "Python is a high-level programming language known for readability.",
    "Machine learning algorithms improve through experience without explicit programming.",
    "Deep learning is a subset of machine learning using neural networks.",
    "The transformer architecture revolutionized natural language processing.",
    "BERT uses bidirectional attention to understand context in both directions.",
    "GPT generates text by predicting the next token in a sequence.",
    "Vector databases store embeddings and enable fast similarity search.",
    "RAG combines retrieval systems with language models for knowledge access.",
    "Fine-tuning adapts a pretrained model to a specific downstream task.",
    "Cosine similarity measures the angle between two vectors in space.",
    "The attention mechanism lets models focus on relevant parts of input.",
    "Tokenization converts raw text into numerical tokens for models.",
    "Embeddings map words or sentences to dense low-dimensional vectors.",
    "Gradient descent optimizes model parameters by following the loss gradient.",
    "Overfitting occurs when a model memorizes training data but fails to generalize.",
]

corpus_embeddings = model.encode(corpus, show_progress_bar=False)
print(f"Corpus: {len(corpus)} documents")
print(f"Embeddings shape: {corpus_embeddings.shape}")
print()

def semantic_search(query, corpus, corpus_embeddings, model, top_k=3):
    query_embedding  = model.encode([query])
    similarities     = cosine_similarity(query_embedding, corpus_embeddings)[0]
    top_indices      = np.argsort(similarities)[::-1][:top_k]
    results = []
    for idx in top_indices:
        results.append({
            "text":  corpus[idx],
            "score": similarities[idx],
            "rank":  len(results) + 1
        })
    return results

queries = [
    "How do neural networks learn?",
    "What is the purpose of tokenization?",
    "How can I prevent overfitting?",
]

for query in queries:
    results = semantic_search(query, corpus, corpus_embeddings, model)
    print(f"Query: '{query}'")
    for r in results:
        print(f"  [{r['rank']}] {r['score']:.3f}  {r['text']}")
    print()

Enter fullscreen mode Exit fullscreen mode

Output:

Query: 'How do neural networks learn?'
  [1] 0.823  Machine learning algorithms improve through experience without explicit programming.
  [2] 0.798  Gradient descent optimizes model parameters by following the loss gradient.
  [3] 0.776  Deep learning is a subset of machine learning using neural networks.

Query: 'What is the purpose of tokenization?'
  [1] 0.891  Tokenization converts raw text into numerical tokens for models.
  [2] 0.712  Embeddings map words or sentences to dense low-dimensional vectors.
  [3] 0.634  BERT uses bidirectional attention to understand context in both directions.

Enter fullscreen mode Exit fullscreen mode


Vector Databases: Production-Grade Storage

print("Why Not Just Use NumPy Cosine Similarity?")
print()
print("  For 1,000 documents: NumPy works fine.")
print("  For 1,000,000 documents: computing similarity against all docs")
print("  at every query is slow and memory-intensive.")
print()
print("  1M docs × 384 dims × 4 bytes = 1.5 GB just for storage.")
print("  Brute-force search = 1M dot products per query.")
print("  At 100 queries/second: 100M dot products/second.")
print()
print("Vector databases solve this with approximate nearest neighbor (ANN) indexes.")
print()

ann_algorithms = {
    "HNSW": (
        "Hierarchical Navigable Small World",
        "Graph-based. Fast search. High recall. Most popular.",
        "Used by: Chroma, Qdrant, Pinecone"
    ),
    "IVF":  (
        "Inverted File Index",
        "Cluster-based. Good for billions of vectors.",
        "Used by: Faiss, Milvus"
    ),
    "LSH":  (
        "Locality Sensitive Hashing",
        "Hash-based. Very fast. Lower recall.",
        "Good for: streaming, exact doesn't matter"
    ),
    "ScaNN":(
        "Scalable Nearest Neighbors",
        "Google's algorithm. Quantization-aware.",
        "Used by: Google Search, YouTube recommendations"
    ),
}

print("ANN Index Algorithms:")
for algo, (full_name, description, usage) in ann_algorithms.items():
    print(f"  {algo:<6}: {full_name}")
    print(f"         {description}")
    print(f"         {usage}")
    print()

Enter fullscreen mode Exit fullscreen mode


ChromaDB: Simplest Vector Database

print("ChromaDB: Simplest vector database for development")
print()
print("pip install chromadb")
print()

chroma_code = """
import chromadb
from sentence_transformers import SentenceTransformer

# Initialize
client     = chromadb.Client()
collection = client.create_collection(
    name="my_docs",
    metadata={"hnsw:space": "cosine"}
)

# Add documents
documents = [
    "Machine learning learns from data.",
    "Deep learning uses neural networks.",
    "Python is great for data science.",
]

model = SentenceTransformer("all-MiniLM-L6-v2")
embeddings = model.encode(documents).tolist()

collection.add(
    documents  = documents,
    embeddings = embeddings,
    ids        = ["doc_1", "doc_2", "doc_3"],
    metadatas  = [{"source": "wiki"}, {"source": "wiki"}, {"source": "blog"}]
)

# Query
query = "How do neural networks work?"
query_embedding = model.encode([query]).tolist()

results = collection.query(
    query_embeddings = query_embedding,
    n_results        = 2,
    where            = {"source": "wiki"}  # metadata filtering!
)

print(results["documents"])
# [['Deep learning uses neural networks.', 'Machine learning learns from data.']]
"""

print(chroma_code)
print()
print("ChromaDB features:")
print("  Runs in-memory or persistent on disk")
print("  Metadata filtering (filter by source, date, category)")
print("  Built-in HNSW indexing")
print("  Python-first API")
print("  Perfect for prototyping RAG systems")

Enter fullscreen mode Exit fullscreen mode


FAISS: Production-Scale Search

print("FAISS: Facebook AI Similarity Search")
print()
print("pip install faiss-cpu  # or faiss-gpu")
print()

faiss_code = """
import faiss
import numpy as np
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("all-MiniLM-L6-v2")

# Encode corpus
corpus    = [...]  # your documents
embeddings = model.encode(corpus).astype("float32")

# Normalize for cosine similarity (makes L2 = cosine)
faiss.normalize_L2(embeddings)

# Build HNSW index
dim   = embeddings.shape[1]  # 384
index = faiss.IndexHNSWFlat(dim, 32)  # 32 neighbors per layer
index.add(embeddings)

print(f"Index contains {index.ntotal} vectors")

# Search
query     = "How does attention work?"
query_emb = model.encode([query]).astype("float32")
faiss.normalize_L2(query_emb)

distances, indices = index.search(query_emb, k=5)

print("Top 5 results:")
for dist, idx in zip(distances[0], indices[0]):
    print(f"  sim={dist:.3f}  {corpus[idx]}")

# Save and load
faiss.write_index(index, "my_index.faiss")
index = faiss.read_index("my_index.faiss")
"""

print(faiss_code)
print()
print("FAISS strengths:")
print("  Handles billions of vectors")
print("  GPU acceleration available")
print("  Multiple index types (Flat, IVF, HNSW, PQ)")
print("  Used in production at Facebook, LinkedIn, Spotify")

Enter fullscreen mode Exit fullscreen mode


Choosing the Right Embedding Model

embedding_models = {
    "all-MiniLM-L6-v2": {
        "dims":    384,
        "params":  "22M",
        "speed":   "fastest",
        "quality": "good",
        "use":     "prototyping, high-throughput"
    },
    "all-mpnet-base-v2": {
        "dims":    768,
        "params":  "109M",
        "speed":   "moderate",
        "quality": "better",
        "use":     "production, balanced"
    },
    "text-embedding-3-small": {
        "dims":    1536,
        "params":  "OpenAI API",
        "speed":   "API call",
        "quality": "excellent",
        "use":     "production, no local GPU"
    },
    "text-embedding-3-large": {
        "dims":    3072,
        "params":  "OpenAI API",
        "speed":   "API call",
        "quality": "best",
        "use":     "high-accuracy requirements"
    },
    "e5-large-v2": {
        "dims":    1024,
        "params":  "335M",
        "speed":   "slow",
        "quality": "excellent",
        "use":     "accuracy-critical, local"
    },
    "bge-large-en-v1.5": {
        "dims":    1024,
        "params":  "335M",
        "speed":   "slow",
        "quality": "excellent",
        "use":     "MTEB leaderboard top performer"
    },
}

print(f"{'Model':<28} {'Dims':>6} {'Params':>12} {'Speed':>10} {'Quality':>10}")
print("=" * 70)
for name, info in embedding_models.items():
    print(f"{name:<28} {info['dims']:>6} {info['params']:>12} "
          f"{info['speed']:>10} {info['quality']:>10}")

print()
print("Rule of thumb:")
print("  Start with all-MiniLM-L6-v2 (fast, free, good enough for most cases)")
print("  Upgrade to mpnet or e5 if quality matters more than speed")
print("  Use OpenAI embeddings if you are already calling the API anyway")
print("  Check MTEB leaderboard for the latest benchmark rankings:")
print("  huggingface.co/spaces/mteb/leaderboard")

Enter fullscreen mode Exit fullscreen mode


Chunking Strategy

print("Chunking: How to Split Documents Before Embedding")
print()
print("Embeddings represent fixed-size text.")
print("Long documents must be split into chunks.")
print("The chunking strategy dramatically affects retrieval quality.")
print()

strategies = {
    "Fixed size": {
        "description": "Split every N characters or tokens",
        "pros":        "Simple, predictable",
        "cons":        "Splits mid-sentence, loses context",
        "use":         "Quick prototype only"
    },
    "Sentence splitting": {
        "description": "Split at sentence boundaries",
        "pros":        "Preserves complete thoughts",
        "cons":        "Variable chunk size, single sentence may lack context",
        "use":         "Short documents, chat logs"
    },
    "Recursive character splitting": {
        "description": "Split at paragraphs → sentences → words as needed",
        "pros":        "Respects document structure",
        "cons":        "Slightly more complex",
        "use":         "Most documents, LangChain default"
    },
    "Semantic chunking": {
        "description": "Split when embedding similarity drops significantly",
        "pros":        "Preserves semantic coherence",
        "cons":        "Slow (encodes every sentence), more complex",
        "use":         "High-quality RAG pipelines"
    },
    "Document-structure aware": {
        "description": "Split at headers/sections/pages",
        "pros":        "Preserves document organization",
        "cons":        "Requires document parsing",
        "use":         "PDFs, technical docs, books"
    },
}

for name, info in strategies.items():
    print(f"  {name}:")
    print(f"    {info['description']}")
    print(f"{info['pros']}")
    print(f"{info['cons']}")
    print(f"    Use: {info['use']}")
    print()

print("Practical recommendation:")
print("  chunk_size=512 tokens, chunk_overlap=64 tokens")
print("  Overlap preserves context at chunk boundaries")
print("  Use LangChain's RecursiveCharacterTextSplitter or similar")

Enter fullscreen mode Exit fullscreen mode


Evaluating Retrieval Quality

def precision_at_k(retrieved, relevant, k):
    retrieved_k = retrieved[:k]
    hits = sum(1 for doc in retrieved_k if doc in relevant)
    return hits / k

def recall_at_k(retrieved, relevant, k):
    retrieved_k = retrieved[:k]
    hits = sum(1 for doc in retrieved_k if doc in relevant)
    return hits / len(relevant) if relevant else 0

def mean_reciprocal_rank(retrieved, relevant):
    for rank, doc in enumerate(retrieved, 1):
        if doc in relevant:
            return 1 / rank
    return 0

retrieved = ["doc_3", "doc_7", "doc_1", "doc_9", "doc_2"]
relevant  = {"doc_1", "doc_3"}

k_values = [1, 2, 3, 5]
print("Retrieval Evaluation Metrics:")
print(f"\nRetrieved: {retrieved}")
print(f"Relevant:  {sorted(relevant)}")
print()
print(f"{'Metric':<25} {'Value':>8}")
print("-" * 35)
for k in k_values:
    p = precision_at_k(retrieved, relevant, k)
    r = recall_at_k(retrieved, relevant, k)
    print(f"  Precision@{k:<3}            {p:>8.3f}")
    print(f"  Recall@{k:<3}               {r:>8.3f}")

mrr = mean_reciprocal_rank(retrieved, relevant)
print(f"  MRR                      {mrr:>8.3f}")
print()
print("Good retrieval system targets:")
print("  Recall@5 > 0.8  (find 80% of relevant docs in top 5)")
print("  Precision@3 > 0.5  (at least half of top 3 are relevant)")
print("  MRR > 0.7  (relevant doc usually appears in top 2)")

Enter fullscreen mode Exit fullscreen mode


A Resource Worth Reading

Pinecone published a free e-book called "Vector Databases" at pinecone.io/learn/vector-database that covers indexing algorithms, embedding models, and production deployment in depth. The content is vendor-neutral despite the source. One of the most comprehensive treatments of vector search available for free. Search "Pinecone vector database guide."

The MTEB (Massive Text Embedding Benchmark) leaderboard at huggingface.co/spaces/mteb/leaderboard ranks embedding models across 56 tasks. It is the definitive resource for selecting embedding models and is updated as new models are released. Check it before choosing a model for production.


Try This

Create vector_search_practice.py.

Part 1: build a semantic search system from scratch. Take any 50+ document dataset (Wikipedia articles, news, documentation). Encode all documents. Accept a query string. Return top 5 most similar documents with scores. Test with 10 different queries. Are the results sensible?

Part 2: compare embedding models. Encode the same 20 sentences with all-MiniLM-L6-v2 and all-mpnet-base-v2. For 5 query-answer pairs, check which model ranks the correct answer higher. Does the larger model improve retrieval?

Part 3: chunking experiment. Take one long document (a Wikipedia article, a paper, a blog post). Split it with three strategies: fixed 200-word chunks, sentence-by-sentence, and 512-token chunks with 64-token overlap. Index all three versions. Run 5 queries. Which chunking produces more coherent retrieved passages?

Part 4: implement ChromaDB. Install ChromaDB. Create a collection. Add 50 documents with metadata (source, date, category). Query with metadata filtering. Return only documents from a specific source. Verify the metadata filter works.


What's Next

You can embed documents and search them by semantic similarity. The next post connects this to language models: Retrieval-Augmented Generation. A user asks a question. You retrieve the relevant documents. You pass them to the LLM as context. The LLM generates an answer grounded in your specific knowledge. This is how production AI assistants actually work.