Vec - Vector Database
High-performance vector database powered by Milvus for similarity search, semantic retrieval, and AI embeddings storage.
Overview
Vec provides a managed vector database service for storing and querying high-dimensional vectors. It's optimized for AI applications including:
- Semantic search and retrieval
- Recommendation systems
- Image and audio similarity
- RAG (Retrieval-Augmented Generation)
- Anomaly detection
Quick Start
import { Tenzro } from '@tenzro/cloud';const client = new Tenzro({apiKey: process.env.TENZRO_API_KEY,projectId: 'your-project-id',});// Get vector database by nameconst vectors = await client.vec.db('knowledge-base');// Insert documents (embeddings auto-generated!)await vectors.upsert({documents: [{ id: 'doc-1', text: 'The quick brown fox jumps over the lazy dog' },{ id: 'doc-2', text: 'Machine learning transforms data into insights' },{ id: 'doc-3', text: 'Vector databases enable semantic search' },]});// Query with natural language (embedding auto-generated!)const results = await vectors.query({text: 'How does machine learning work?',topK: 5,});results.forEach(match => {console.log(match.metadata._text, 'score:', match.score);});
Database Configuration
Dimensions
The vector dimension must match your embedding model:
768- Gemini text-embedding-004 (default)1536- OpenAI text-embedding-3-small3072- OpenAI text-embedding-3-large384- all-MiniLM-L6-v2
Metric Types
| Metric | Description | Use Case |
|---|---|---|
COSINE | Cosine similarity (normalized) | Text embeddings, semantic search |
L2 | Euclidean distance | Image features, spatial data |
IP | Inner product | Recommendation, when vectors are normalized |
Index Types
| Index | Description | Best For |
|---|---|---|
HNSW | Hierarchical Navigable Small World | Best balance of speed and accuracy |
IVF_FLAT | Inverted File with Flat quantization | High accuracy, moderate speed |
IVF_SQ8 | Inverted File with Scalar Quantization | Memory efficient, large datasets |
SDK Reference
Get Database
// Get existing database by nameconst vectors = await client.vec.db('knowledge-base');
Upsert Documents (Auto-Embedding)
// Just provide text - embeddings are auto-generated!await vectors.upsert({documents: [{ id: 'doc-1', text: 'Your document text', metadata: { category: 'tech' } },{ id: 'doc-2', text: 'Another document' },]});// Returns: { count: number }
Query (Auto-Embedding)
// Natural language query - embedding auto-generated!const results = await vectors.query({text: 'How does machine learning work?',topK: 10, // Optional: default 10filter: { category: 'tech' }, // Optional: metadata filter});// Returns: SearchResult[]
Manual Insert Vectors
// If you have pre-computed vectorsconst result = await vectors.insert({vectors: [{ id: 'doc-1', vector: [0.1, 0.2, ...], metadata: {...} },{ id: 'doc-2', vector: [0.3, 0.4, ...], metadata: {...} },]});// Returns: { count: number }
Manual Search
// If you have a pre-computed query vectorconst results = await vectors.search({vector: [0.1, 0.2, ...],topK: 10,filter: { category: 'tech' },includeMetadata: true,});
Get Vector
const vector = await vectors.getVector('doc-1');
Delete Vector
await vectors.deleteVector('doc-1');
Get Statistics
const stats = await vectors.stats();// Returns: { vectorCount, dimension, storageSizeBytes, ... }
RAG Example
Complete example using Vec for Retrieval-Augmented Generation:
import { Tenzro } from '@tenzro/cloud';const client = new Tenzro({apiKey: process.env.TENZRO_API_KEY,projectId: 'your-project-id',});// Get vector databaseconst vectors = await client.vec.db('docs');// Index documents - embeddings auto-generated!async function indexDocuments(docs: { id: string; text: string; title: string }[]) {await vectors.upsert({documents: docs.map(d => ({id: d.id,text: d.text,metadata: { title: d.title },}))});}// RAG query - combines semantic search + AI generationasync function ragQuery(question: string) {// 1. Search for relevant context (embedding auto-generated!)const results = await vectors.query({text: question,topK: 5,});// 2. Build context from search resultsconst context = results.map(r => r.metadata._text).join('\n\n');// 3. Generate answer with AIconst ai = await client.ai.model('gemini-2.5-flash');const response = await ai.infer({prompt: question,systemPrompt: `Answer based on this context:\n\n${context}`,});return response.text;}// Usageawait indexDocuments([{ id: '1', text: 'Machine learning uses algorithms...', title: 'ML Intro' },{ id: '2', text: 'Neural networks consist of...', title: 'Neural Nets' },]);const answer = await ragQuery('How do neural networks work?');console.log(answer);
Metadata Filtering
Vec supports metadata filtering during search:
// Filter by categoryconst results = await vectors.query({text: 'machine learning',topK: 10,filter: { category: 'technology' },});// Multiple conditions (AND)const results = await vectors.query({text: 'recent advances',topK: 10,filter: {category: 'technology',year: 2024,},});
Best Practices
- Batch inserts: Insert vectors in batches of 100-1000 for best performance
- Consistent dimensions: All vectors must have the same dimension
- Index selection: Use HNSW for most cases, IVF_SQ8 for very large datasets
- Metadata indexing: Keep metadata compact for faster filtering
- Regular cleanup: Delete unused vectors to maintain performance
Limits
| Resource | Limit |
|---|---|
| Max dimension | 4096 |
| Max vectors per database | 10 million |
| Max metadata size | 64 KB per vector |
| Max batch insert | 10,000 vectors |
| Max topK | 1000 |