Skill

Setup and Optimize Vector Databases

A vector database setup skill covering Pinecone, Weaviate, and Chroma configuration, index-type selection, and RAG query optimization.

Works with pineconeweaviatechroma

Maintainer of this project? Claim this page to edit the listing.


91
Spark score
out of 100
Updated 7 months ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Implement and configure robust vector database solutions for efficient AI data storage, similarity search, and Retrieval-Augmented Generation (RAG) systems.

Outcomes

What it gets done

01

Select appropriate vector database technology based on scale, performance, and integration needs.

02

Configure indexing strategies (HNSW, IVF, LSH) for optimal search performance.

03

Implement optimized batch operations for data ingestion and querying.

04

Tune database parameters and query strategies for enhanced performance and recall.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-vector-database-setup | bash

Overview

Vector Database Setup Expert

A vector database setup skill covering Pinecone, Weaviate, and Chroma configuration, index-type selection (HNSW, IVF, LSH, flat), and HNSW parameter tuning for RAG and similarity search. It also covers hybrid search, production monitoring, and scalability planning. Use it when setting up or tuning a vector database for embeddings or RAG retrieval, especially when choosing between Pinecone, Weaviate, and Chroma.

What it does

This skill covers vector database architecture, setup, and optimization for AI applications - embedding storage, similarity search, and Retrieval-Augmented Generation systems. It frames database selection around scale requirements, the embedding dimensions your model produces, latency-versus-accuracy tradeoffs, integration fit with your existing stack, and storage/compute/operational cost, and covers four index types by use case: HNSW for high-recall, moderate-scale applications; IVF for large-scale datasets with an acceptable recall tradeoff; LSH for approximate, speed-prioritized search; and flat/brute-force search for small datasets or when perfect accuracy is required.

It provides working setup configurations for three vector databases: Pinecone (index creation with a chosen embedding dimension and cosine metric, metadata indexing for filtered fields, pod-based scaling, and batched vector upserts), Weaviate (a schema-driven class definition using the text2vec-openai vectorizer and qna-openai module for built-in question answering), and Chroma (a persistent local client with a custom OpenAI embedding function and batched document adds). Performance guidance covers HNSW parameter tuning (ef and efConstruction for recall versus speed, maxConnections for recall versus memory) and query optimization strategies - pre-filtering (recommended for high-selectivity filters) versus post-filtering, and hybrid search that combines vector similarity with keyword search and re-ranks the merged results.

Production guidance covers a Docker Compose setup for local Weaviate development and a health-monitoring pattern that reports vector count, index size, p95 query latency, and memory usage. Best practices span data management (batch operations for throughput, indexing only frequently filtered metadata fields, normalizing vectors for cosine similarity, using namespaces to isolate data types), security (API key rotation, network isolation and VPCs, audit logging, rate limiting), and scalability planning (budgeting for 2-3x growth in vectors and query volume, monitoring index-build and query-latency trends, and considering multi-region deployment for global applications).

def upsert_vectors_batch(vectors_data, batch_size=100):
    for i in range(0, len(vectors_data), batch_size):
        batch = vectors_data[i:i + batch_size]
        index.upsert(vectors=batch, namespace="documents")

When to use - and when NOT to

Use this skill when setting up or tuning a vector database for embeddings, similarity search, or RAG - choosing between Pinecone, Weaviate, and Chroma, selecting an index type for your scale and recall needs, tuning HNSW parameters, or adding hybrid search and production monitoring.

It is not a fit for choosing or training the embedding model itself - the guidance assumes you already have embeddings (or an embedding function like OpenAI's) and focuses on storing, indexing, and querying them efficiently.

Inputs and outputs

Inputs are your embedding dimensions, expected vector count and query volume, and latency/accuracy requirements. Outputs are working setup code for Pinecone, Weaviate, or Chroma, tuned index configuration, pre-filtering and hybrid-search query patterns, a Docker Compose file for local development, and a health-check function reporting vector count, index size, and p95 latency.

Integrations

Covers Pinecone, Weaviate, and Chroma as vector database backends, with OpenAI embedding models (text-embedding-ada-002) used as the default vectorizer in the Weaviate and Chroma setup examples.

Who it's for

AI engineers setting up embedding storage or RAG retrieval who need concrete, working configuration for a specific vector database rather than starting from each database's separate documentation - including index-type selection, HNSW tuning, hybrid search, and production monitoring and security practices.

Source README

Vector Database Setup Expert

You are an expert in vector database architecture, setup, and optimization. You specialize in designing and implementing vector storage solutions for AI applications, including embedding storage, similarity search, and Retrieval-Augmented Generation (RAG) systems. You understand the nuances of different vector database technologies, indexing strategies, and performance optimization techniques.

Core Principles

Vector Database Selection Criteria

  • Scale Requirements: Choose based on expected data volume and query throughput
  • Embedding Dimensions: Ensure database supports your model's vector dimensions
  • Performance Needs: Consider latency vs. accuracy tradeoffs with different index types
  • Integration Requirements: Evaluate compatibility with your existing tech stack
  • Cost Considerations: Factor in storage, compute, and operational costs

Index Types and Use Cases

  • HNSW (Hierarchical Navigable Small World): Best for high-recall, moderate scale applications
  • IVF (Inverted File): Suitable for large-scale datasets with acceptable recall tradeoffs
  • LSH (Locality Sensitive Hashing): Good for approximate searches with speed priority
  • Flat/Brute Force: Use for small datasets or when perfect accuracy is required

Database-Specific Setup Configurations

Pinecone Setup

import pinecone

### Initialize Pinecone
pinecone.init(
    api_key="your-api-key",
    environment="your-environment"
)

### Create index with optimal settings
index_name = "document-embeddings"
if index_name not in pinecone.list_indexes():
    pinecone.create_index(
        name=index_name,
        dimension=1536,  # OpenAI ada-002 dimensions
        metric="cosine",
        metadata_config={
            "indexed": ["document_type", "category", "timestamp"]
        },
        pods=1,
        replicas=1,
        pod_type="p1.x1"  # Choose based on performance needs
    )

index = pinecone.Index(index_name)

### Optimized batch upsert
def upsert_vectors_batch(vectors_data, batch_size=100):
    for i in range(0, len(vectors_data), batch_size):
        batch = vectors_data[i:i + batch_size]
        index.upsert(vectors=batch, namespace="documents")

Weaviate Setup

import weaviate
import json

client = weaviate.Client(
    url="http://localhost:8080",
    additional_headers={
        "X-OpenAI-Api-Key": "your-openai-key"
    }
)

### Define schema with vectorizer
schema = {
    "classes": [{
        "class": "Document",
        "description": "A document with semantic search capabilities",
        "vectorizer": "text2vec-openai",
        "moduleConfig": {
            "text2vec-openai": {
                "model": "ada",
                "modelVersion": "002",
                "type": "text"
            },
            "qna-openai": {
                "model": "text-davinci-003"
            }
        },
        "properties": [
            {
                "name": "content",
                "dataType": ["text"],
                "description": "The content of the document"
            },
            {
                "name": "title",
                "dataType": ["string"],
                "description": "Document title"
            },
            {
                "name": "category",
                "dataType": ["string"],
                "description": "Document category"
            }
        ]
    }]
}

client.schema.create(schema)

Chroma Setup

import chromadb
from chromadb.config import Settings

### Production setup with persistence
client = chromadb.Client(Settings(
    chroma_db_impl="duckdb+parquet",
    persist_directory="./chroma_db"
))

### Create collection with custom embedding function
collection = client.create_collection(
    name="documents",
    embedding_function=chromadb.utils.embedding_functions.OpenAIEmbeddingFunction(
        api_key="your-openai-key",
        model_name="text-embedding-ada-002"
    ),
    metadata={"hnsw:space": "cosine"}
)

### Optimized batch operations
def add_documents_batch(texts, metadatas, ids, batch_size=166):
    for i in range(0, len(texts), batch_size):
        collection.add(
            documents=texts[i:i+batch_size],
            metadatas=metadatas[i:i+batch_size],
            ids=ids[i:i+batch_size]
        )

Performance Optimization

Index Configuration Tuning

### HNSW Parameters (Weaviate example)
vectorIndexConfig:
  ef: 64              # Higher = better recall, slower queries
  efConstruction: 128 # Higher = better index quality, slower indexing
  maxConnections: 32  # Higher = better recall, more memory
  vectorCacheMaxObjects: 2000000
  cleanupIntervalSeconds: 300

Query Optimization Strategies

### Pre-filtering vs Post-filtering
### Pre-filtering (recommended for high selectivity)
results = index.query(
    vector=query_vector,
    top_k=10,
    filter={
        "category": {"$eq": "technical"},
        "timestamp": {"$gte": "2023-01-01"}
    },
    include_metadata=True
)

### Hybrid search combining vector and keyword search
def hybrid_search(query_text, query_vector, alpha=0.7):
    vector_results = collection.query(
        query_embeddings=[query_vector],
        n_results=20
    )
    
    keyword_results = collection.query(
        query_texts=[query_text],
        n_results=20
    )
    
    # Combine and re-rank results
    return combine_results(vector_results, keyword_results, alpha)

Production Deployment Patterns

Docker Compose for Local Development

version: '3.8'
services:
  weaviate:
    command:
      - --host
      - 0.0.0.0
      - --port
      - '8080'
      - --scheme
      - http
    image: semitechnologies/weaviate:1.21.2
    ports:
      - "8080:8080"
    volumes:
      - weaviate_data:/var/lib/weaviate
    environment:
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'text2vec-openai'
      ENABLE_MODULES: 'text2vec-openai,qna-openai'
      OPENAI_APIKEY: $OPENAI_APIKEY
    restart: on-failure:0
volumes:
  weaviate_data:

Monitoring and Health Checks

### Database health monitoring
def monitor_vector_db_health():
    try:
        # Test connection
        stats = client.get_collection_stats()
        
        # Check key metrics
        metrics = {
            "total_vectors": stats.vector_count,
            "index_size_mb": stats.index_size / (1024 * 1024),
            "query_latency_p95": measure_query_latency(),
            "memory_usage_mb": stats.memory_usage / (1024 * 1024)
        }
        
        return {"status": "healthy", "metrics": metrics}
    except Exception as e:
        return {"status": "unhealthy", "error": str(e)}

def measure_query_latency(sample_queries=10):
    import time
    latencies = []
    
    for _ in range(sample_queries):
        start_time = time.time()
        # Execute sample query
        client.query(vector=[0.1] * 1536, top_k=5)
        latencies.append(time.time() - start_time)
    
    return sorted(latencies)[int(0.95 * len(latencies))]

Best Practices and Recommendations

Data Management

  • Batch Operations: Always use batch operations for better throughput
  • Metadata Strategy: Index only frequently filtered metadata fields
  • Vector Normalization: Normalize vectors when using cosine similarity
  • Namespace Usage: Use namespaces to isolate different data types

Security and Access Control

  • Implement proper API key rotation policies
  • Use network isolation and VPCs in production
  • Enable audit logging for compliance requirements
  • Implement rate limiting to prevent abuse

Scalability Planning

  • Plan for 2-3x growth in vector count and query volume
  • Monitor index build times and query latency trends
  • Implement horizontal scaling strategies early
  • Consider multi-region deployment for global applications

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.