$npx -y skills add spencermarx/open-code-review --skill agentdb-vector-searchImplement semantic vector search with AgentDB for intelligent document retrieval, similarity matching, and context-aware querying. Use when building RAG systems, semantic search engines, or intelligent knowledge bases.
| 1 | # AgentDB Vector Search |
| 2 | |
| 3 | ## What This Skill Does |
| 4 | |
| 5 | Implements vector-based semantic search using AgentDB's high-performance vector database with **150x-12,500x faster** operations than traditional solutions. Features HNSW indexing, quantization, and sub-millisecond search (<100µs). |
| 6 | |
| 7 | ## Prerequisites |
| 8 | |
| 9 | - Node.js 18+ |
| 10 | - AgentDB v1.0.7+ (via agentic-flow or standalone) |
| 11 | - OpenAI API key (for embeddings) or custom embedding model |
| 12 | |
| 13 | ## Quick Start with CLI |
| 14 | |
| 15 | ### Initialize Vector Database |
| 16 | |
| 17 | ```bash |
| 18 | # Initialize with default dimensions (1536 for OpenAI ada-002) |
| 19 | npx agentdb@latest init ./vectors.db |
| 20 | |
| 21 | # Custom dimensions for different embedding models |
| 22 | npx agentdb@latest init ./vectors.db --dimension 768 # sentence-transformers |
| 23 | npx agentdb@latest init ./vectors.db --dimension 384 # all-MiniLM-L6-v2 |
| 24 | |
| 25 | # Use preset configurations |
| 26 | npx agentdb@latest init ./vectors.db --preset small # <10K vectors |
| 27 | npx agentdb@latest init ./vectors.db --preset medium # 10K-100K vectors |
| 28 | npx agentdb@latest init ./vectors.db --preset large # >100K vectors |
| 29 | |
| 30 | # In-memory database for testing |
| 31 | npx agentdb@latest init ./vectors.db --in-memory |
| 32 | ``` |
| 33 | |
| 34 | ### Query Vector Database |
| 35 | |
| 36 | ```bash |
| 37 | # Basic similarity search |
| 38 | npx agentdb@latest query ./vectors.db "[0.1,0.2,0.3,...]" |
| 39 | |
| 40 | # Top-k results |
| 41 | npx agentdb@latest query ./vectors.db "[0.1,0.2,0.3]" -k 10 |
| 42 | |
| 43 | # With similarity threshold (cosine similarity) |
| 44 | npx agentdb@latest query ./vectors.db "0.1 0.2 0.3" -t 0.75 -m cosine |
| 45 | |
| 46 | # Different distance metrics |
| 47 | npx agentdb@latest query ./vectors.db "[...]" -m euclidean # L2 distance |
| 48 | npx agentdb@latest query ./vectors.db "[...]" -m dot # Dot product |
| 49 | |
| 50 | # JSON output for automation |
| 51 | npx agentdb@latest query ./vectors.db "[...]" -f json -k 5 |
| 52 | |
| 53 | # Verbose output with distances |
| 54 | npx agentdb@latest query ./vectors.db "[...]" -v |
| 55 | ``` |
| 56 | |
| 57 | ### Import/Export Vectors |
| 58 | |
| 59 | ```bash |
| 60 | # Export vectors to JSON |
| 61 | npx agentdb@latest export ./vectors.db ./backup.json |
| 62 | |
| 63 | # Import vectors from JSON |
| 64 | npx agentdb@latest import ./backup.json |
| 65 | |
| 66 | # Get database statistics |
| 67 | npx agentdb@latest stats ./vectors.db |
| 68 | ``` |
| 69 | |
| 70 | ## Quick Start with API |
| 71 | |
| 72 | ```typescript |
| 73 | import { createAgentDBAdapter, computeEmbedding } from 'agentic-flow/reasoningbank'; |
| 74 | |
| 75 | // Initialize with vector search optimizations |
| 76 | const adapter = await createAgentDBAdapter({ |
| 77 | dbPath: '.agentdb/vectors.db', |
| 78 | enableLearning: false, // Vector search only |
| 79 | enableReasoning: true, // Enable semantic matching |
| 80 | quantizationType: 'binary', // 32x memory reduction |
| 81 | cacheSize: 1000, // Fast retrieval |
| 82 | }); |
| 83 | |
| 84 | // Store document with embedding |
| 85 | const text = "The quantum computer achieved 100 qubits"; |
| 86 | const embedding = await computeEmbedding(text); |
| 87 | |
| 88 | await adapter.insertPattern({ |
| 89 | id: '', |
| 90 | type: 'document', |
| 91 | domain: 'technology', |
| 92 | pattern_data: JSON.stringify({ |
| 93 | embedding, |
| 94 | text, |
| 95 | metadata: { category: "quantum", date: "2025-01-15" } |
| 96 | }), |
| 97 | confidence: 1.0, |
| 98 | usage_count: 0, |
| 99 | success_count: 0, |
| 100 | created_at: Date.now(), |
| 101 | last_used: Date.now(), |
| 102 | }); |
| 103 | |
| 104 | // Semantic search with MMR (Maximal Marginal Relevance) |
| 105 | const queryEmbedding = await computeEmbedding("quantum computing advances"); |
| 106 | const results = await adapter.retrieveWithReasoning(queryEmbedding, { |
| 107 | domain: 'technology', |
| 108 | k: 10, |
| 109 | useMMR: true, // Diverse results |
| 110 | synthesizeContext: true, // Rich context |
| 111 | }); |
| 112 | ``` |
| 113 | |
| 114 | ## Core Features |
| 115 | |
| 116 | ### 1. Vector Storage |
| 117 | ```typescript |
| 118 | // Store with automatic embedding |
| 119 | await db.storeWithEmbedding({ |
| 120 | content: "Your document text", |
| 121 | metadata: { source: "docs", page: 42 } |
| 122 | }); |
| 123 | ``` |
| 124 | |
| 125 | ### 2. Similarity Search |
| 126 | ```typescript |
| 127 | // Find similar documents |
| 128 | const similar = await db.findSimilar("quantum computing", { |
| 129 | limit: 5, |
| 130 | minScore: 0.75 |
| 131 | }); |
| 132 | ``` |
| 133 | |
| 134 | ### 3. Hybrid Search (Vector + Metadata) |
| 135 | ```typescript |
| 136 | // Combine vector similarity with metadata filtering |
| 137 | const results = await db.hybridSearch({ |
| 138 | query: "machine learning models", |
| 139 | filters: { |
| 140 | category: "research", |
| 141 | date: { $gte: "2024-01-01" } |
| 142 | }, |
| 143 | limit: 20 |
| 144 | }); |
| 145 | ``` |
| 146 | |
| 147 | ## Advanced Usage |
| 148 | |
| 149 | ### RAG (Retrieval Augmented Generation) |
| 150 | ```typescript |
| 151 | // Build RAG pipeline |
| 152 | async function ragQuery(question: string) { |
| 153 | // 1. Get relevant context |
| 154 | const context = await db.searchSimilar( |
| 155 | await embed(question), |
| 156 | { limit: 5, threshold: 0.7 } |
| 157 | ); |
| 158 | |
| 159 | // 2. Generate answer with context |
| 160 | const prompt = `Context: ${context.map(c => c.text).join('\n')} |
| 161 | Question: ${question}`; |
| 162 | |
| 163 | return await llm.generate(prompt); |
| 164 | } |
| 165 | ``` |
| 166 | |
| 167 | ### Batch Operations |
| 168 | ```typescript |
| 169 | // Efficient batch storage |
| 170 | await db.batchStore(documents.map(doc => ({ |
| 171 | text: doc.content, |
| 172 | embedding: doc.vector, |
| 173 | metadata: doc.meta |
| 174 | }))); |
| 175 | ``` |
| 176 | |
| 177 | ## MCP Server Integration |
| 178 | |
| 179 | ```bash |
| 180 | # Start AgentDB MCP server for Claude Code |
| 181 | npx agentdb@latest mcp |
| 182 | |
| 183 | # Add to Claude Code (one-time se |