← Back to all products

Vector Search Setup

$29

Python vector search with index building, cosine similarity, and approximate nearest neighbor search.

📁 11 files
MarkdownPython

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 11 files

vector-search-setup/ ├── LICENSE ├── README.md ├── examples/ │ ├── basic_usage.py │ └── sample_documents.jsonl ├── free-sample.zip ├── guide/ │ ├── 01_features.md │ ├── 02_project-structure.md │ ├── 03_data-format.md │ └── 04_faq.md ├── index.html └── src/ └── vector_search_setup.py

📖 Documentation Preview README excerpt

Vector Search Setup

Python vector search engine with index building, cosine similarity, LSH-powered approximate nearest neighbors, and a query API. All math from scratch. Zero dependencies.

Part of the AI Toolkit collection by [CodeVault](https://ai-toolkit.codevault.dev).

Features

  • Cosine similarity — Manual implementation of dot product, magnitude, and cosine similarity
  • LSH indexing — Locality-sensitive hashing for sub-linear approximate nearest neighbor search
  • Exact search — Brute-force search for small indexes where perfect recall matters
  • Text-to-vector — Hashed bag-of-words encoder converts text to fixed-dimension vectors
  • Vocabulary builder — Automatic vocabulary extraction from your document corpus
  • Index persistence — Save and load indexes to/from JSON files
  • Performance benchmark — Compare exact vs. approximate search speed and recall
  • CLI interface — Build indexes, query them, and run benchmarks from the terminal

Quick Start


# Run the interactive demo with built-in sample data
python src/vector_search_setup.py --demo

# Build an index from a JSONL file
python src/vector_search_setup.py --build-index data.jsonl --output my_index.json

# Query an existing index
python src/vector_search_setup.py --query "machine learning algorithms" --index my_index.json --top-k 5

# Run performance benchmark
python src/vector_search_setup.py --benchmark --dim 128 --num-vectors 5000

Project Structure


vector-search-setup/
├── README.md
├── LICENSE
├── src/
│   └── vector_search_setup.py    # Core engine (~400 lines)
└── examples/
    ├── basic_usage.py             # Programmatic usage example
    └── sample_documents.jsonl     # Sample data for index building

CLI Reference

FlagDescription
--demoRun demo with built-in sample data
--build-index FILEBuild index from JSONL file
--output FILEOutput path for built index (default: index.json)
--query TEXTSearch query text
--index FILEPath to a saved index file
--top-k NNumber of results (default: 5)
--exactUse exact (brute force) search
--benchmarkRun performance benchmark
--dim NVector dimension for benchmark (default: 64)
--num-vectors NNumber of vectors for benchmark (default: 1000)

... continues with setup instructions, usage examples, and more.

📄 Code Sample .py preview

examples/basic_usage.py#!/usr/bin/env python3 """ Basic usage example for the Vector Search Setup. Demonstrates: - Building an index from documents - Running exact and approximate searches - Saving and loading an index - Adding documents incrementally - Using the vector math utilities directly """ import json import sys import tempfile from pathlib import Path # Allow running from the examples/ directory sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src")) from vector_search_setup import ( VectorIndex, cosine_similarity, normalize, text_to_vector, build_vocabulary, centroid, ) def demo_build_and_search() -> None: """Build an index from sample documents and run searches.""" print("=== Build Index & Search ===\n") documents = [ {"id": "py-001", "text": "Python is a versatile programming language used for web development, data science, and automation.", "metadata": {"lang": "python"}}, {"id": "js-001", "text": "JavaScript powers interactive web pages and runs in every modern browser.", "metadata": {"lang": "javascript"}}, {"id": "ml-001", "text": "Machine learning models learn patterns from training data to make predictions on new data.", "metadata": {"topic": "ml"}}, {"id": "db-001", "text": "PostgreSQL is an advanced open source relational database with strong SQL compliance.", "metadata": {"topic": "database"}}, {"id": "ai-001", "text": "Large language models generate text by predicting the next token in a sequence.", "metadata": {"topic": "ai"}}, {"id": "dv-001", "text": "Docker containers package applications with all dependencies for consistent deployment.", "metadata": {"topic": "devops"}}, {"id": "ml-002", "text": "Neural networks consist of layers of neurons that transform input data through learned weights.", "metadata": {"topic": "ml"}},
Buy Now — $29 Back to Products