[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3
SEQ. 4

Vector Databases Deep Dive

🧠 Agent Memory10 min80 BASE XP

Choosing and Using Vector Databases

Vector databases are the backbone of agent long-term memory. They store embeddings (numerical representations of text) and enable similarity search.

Vector Database Comparison

DatabaseTypeMax VectorsUnique StrengthBest For
PineconeManaged SaaSBillionsZero-ops, fast scalingProduction, startups
WeaviateOpen + ManagedHundreds of millionsBuilt-in vectorizationFull-stack vector apps
ChromaOpen-sourceMillionsSimple API, embedded modePrototyping, local dev
QdrantOpen-sourceBillionsRust performance, filteringHigh-performance search
pgvectorPostgreSQL extensionMillionsUses existing PostgresAdding vectors to existing apps

Key Concepts

  • Embeddings: Convert text to a fixed-length vector (e.g., 1536 dimensions). Similar text produces similar vectors.
  • Similarity Search: Find the K nearest vectors to a query vector. Common metrics: cosine similarity, dot product, L2 distance.
  • Metadata Filtering: Combine vector search with traditional filters (e.g., "find similar docs WHERE category = 'legal'").
  • Namespaces/Collections: Partition vectors by tenant, project, or type for isolation and performance.

Integration Pattern

// Agent Memory with Vector DB:
async function rememberAndRecall(agent, userMessage) {
  // 1. Search for relevant memories
  const memories = await vectorDB.query({
    vector: await embed(userMessage),
    topK: 5,
    filter: { userId: user.id }
  });
  
  // 2. Inject memories into context
  const context = memories.map(m => m.text).join('\n');
  
  // 3. Generate response with memory context
  const response = await llm.generate({
    system: `You have access to past conversations: ${context}`,
    user: userMessage
  });
  
  // 4. Store this interaction as new memory
  await vectorDB.upsert({
    id: generateId(),
    vector: await embed(userMessage + response),
    metadata: { userId: user.id, timestamp: Date.now() }
  });
  
  return response;
}
💡 Key Insight: Start with Chroma for prototyping (runs in-process, no server needed), then migrate to Pinecone or Qdrant for production. The API patterns are similar enough that migration is straightforward.
SYNAPSE VERIFICATION
QUERY 1 // 2
What is the recommended vector database for prototyping and local development?
Pinecone
Chroma (simple API, runs embedded, no server required)
Amazon Neptune
MongoDB
Watch: 139x Rust Speedup
Vector Databases Deep Dive | Agent Memory — AI Agents Academy