This repository contains comprehensive study materials, practical implementations, and hands-on projects for understanding and working with vector databases, focusing on fundamental indexing algorithms and retrieval techniques.
Vector databases are specialized databases designed to store, index, and query high-dimensional vector data efficiently. They are essential for modern AI applications including semantic search, recommendation systems, RAG (Retrieval-Augmented Generation) systems, and similarity matching.
This repository provides:
- Algorithm implementations of core indexing techniques (TF-IDF, BM25, LSH)
- Interactive notebooks for learning fundamental concepts and practical applications
- Modular code structures for production-ready implementations
- Comprehensive documentation and educational materials
Interactive Jupyter notebooks for learning and experimentation:
Vector-Database.ipynb- Comprehensive vector database tutorial and conceptsvdb-indexing.001.lsh.ipynb- Locality-Sensitive Hashing (LSH) indexing techniquesvdb-indexing.002.tf-idf.ipynb- TF-IDF algorithm theory and implementationvdb-indexing.003.bm25.ipynb- BM25 ranking function with detailed analysisWeaviate-Collections.ipynb- Weaviate collections tutorial (legacy)Weaviate-Modules.ipynb- Weaviate modules tutorial (legacy)
Production-ready implementations of core indexing algorithms:
tfidf_calculator.py- Core TF-IDF algorithm implementationdocument_ranker.py- Document ranking using TF-IDF scoressimple_tfidf_example.py- Basic usage exampleMakefile- Build and test automationrequirements.txt- Python dependenciesREADME.md- Detailed documentation and usage guide
bm25_calculator.py- Core BM25 algorithm implementationdocument_ranker.py- Document ranking using BM25 scoressimple_bm25_example.py- Basic usage exampleMakefile- Build and test automationrequirements.txt- Python dependenciesREADME.md- Detailed documentation and usage guide
Start with the educational notebooks:
# Navigate to notebooks directory
cd notebooks/
# Start with fundamentals
jupyter notebook Vector-Database.ipynb
# Learn indexing algorithms
jupyter notebook vdb-indexing.002.tf-idf.ipynb # TF-IDF theory and practice
jupyter notebook vdb-indexing.003.bm25.ipynb # BM25 ranking function
jupyter notebook vdb-indexing.001.lsh.ipynb # LSH for approximate searchTry the production-ready implementations:
# Test TF-IDF implementation
cd indexes/tf-idf/
python simple_tfidf_example.py
# Test BM25 implementation
cd ../bm25/
python simple_bm25_example.py
# Build and test with make
make testUse sample data or bring your own:
# Create sample data for testing
python -c "
from indexes.bm25.bm25_calculator import BM25Calculator
# Use sample documents
documents = [
'Machine learning is transforming data analysis',
'Natural language processing enables text understanding',
'Deep learning uses neural networks for pattern recognition',
'Computer vision analyzes images and visual data',
'Data science combines statistics and programming'
]
# Create and train BM25 model
bm25 = BM25Calculator()
bm25.fit(documents)
# Query the model
results = bm25.rank_documents('science technology', top_k=3)
for rank, (idx, doc, score) in enumerate(results, 1):
print(f'{rank}. {doc} (score: {score:.3f})')
"- Foundation: Start with
Vector-Database.ipynbto understand vector database fundamentals - Algorithms: Learn TF-IDF and BM25 through the interactive notebooks
- Hands-on: Run the example scripts in each
indexes/implementation - Build: Use the modular implementations in your own projects
- Advanced: Explore LSH and approximate search techniques
- Python 3.8+ (recommended: Python 3.12.9)
- Jupyter Notebook environment for interactive learning
- Python packages: See
requirements.txtin each implementation directory- Core:
numpy,pandas,matplotlib,seaborn - Additional:
scikit-learn(for comparisons and validation)
- Core:
# Create virtual environment (recommended)
python -m venv vdb-env
source vdb-env/bin/activate # On Windows: vdb-env\Scripts\activate
# Install dependencies for specific implementations
cd indexes/tf-idf && pip install -r requirements.txt
cd ../bm25 && pip install -r requirements.txt
# For notebooks, install additional dependencies
pip install jupyter matplotlib seaborn scikit-learn- Use Case: Document similarity and basic information retrieval
- Strengths: Simple, interpretable, good baseline for text analysis
- Implementation: Full calculation with normalization options
- Features: Document ranking, similarity scoring, term importance analysis
- Use Case: Advanced information retrieval and search ranking
- Strengths: Handles document length normalization, tunable parameters
- Implementation: Production-ready with detailed parameter analysis
- Features: Probabilistic ranking, length normalization, parameter optimization
- Use Case: Approximate similarity search for large-scale data
- Strengths: Sub-linear query time, scalable to massive datasets
- Implementation: Multiple hash family implementations
- Features: Configurable precision/recall trade-offs, collision analysis
- Educational: Step-by-step explanations with mathematical foundations
- Visual: Rich visualizations showing algorithm behavior and parameter effects
- Modular: Clean, reusable implementations suitable for production
- Testable: Comprehensive examples and test cases
- Comparative: Side-by-side algorithm comparisons and analysis