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 name
const 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-small
  • 3072 - OpenAI text-embedding-3-large
  • 384 - all-MiniLM-L6-v2

Metric Types

MetricDescriptionUse Case
COSINECosine similarity (normalized)Text embeddings, semantic search
L2Euclidean distanceImage features, spatial data
IPInner productRecommendation, when vectors are normalized

Index Types

IndexDescriptionBest For
HNSWHierarchical Navigable Small WorldBest balance of speed and accuracy
IVF_FLATInverted File with Flat quantizationHigh accuracy, moderate speed
IVF_SQ8Inverted File with Scalar QuantizationMemory efficient, large datasets

SDK Reference

Get Database

// Get existing database by name
const 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 10
filter: { category: 'tech' }, // Optional: metadata filter
});
// Returns: SearchResult[]

Manual Insert Vectors

// If you have pre-computed vectors
const 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 vector
const 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 database
const 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 generation
async 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 results
const context = results
.map(r => r.metadata._text)
.join('\n\n');
// 3. Generate answer with AI
const 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;
}
// Usage
await 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 category
const 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

ResourceLimit
Max dimension4096
Max vectors per database10 million
Max metadata size64 KB per vector
Max batch insert10,000 vectors
Max topK1000