Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

abhishekkrthakur/search

Repository files navigation

Hybrid Search

Vespa + FastAPI demo that now covers both lexical BM25 and dense semantic retrieval with a hybrid (RRF) ranking option.

Tutorial Series

More coming soon!

Questions or requests? Open a GitHub issue.

What’s Included

  • bm25.py: Vespa application package with multiple BM25 rank profiles for lexical experiments.
  • hybrid.py: Vespa package with BM25 + HNSW vectors and three rank profiles (bm25, semantic, fusion using reciprocal rank fusion).
  • feed.py: Deploys the hybrid package to a local Vespa Docker container, writes the app to ./vespa_app_hybrid, encodes documents with all-MiniLM-L6-v2, and streams FineWeb into Vespa.
  • ui.py + templates/ + static/: FastAPI-powered UI that lets you pick ranking modes and handles query embedding for semantic/hybrid searches.

Prerequisites

  • Python 3.10+
  • Docker or Podman (for Vespa deployment)
  • uv package manager (recommended)
  • Network access to pull HuggingFace FineWeb and the SentenceTransformer model

Install Dependencies

uv sync

Deploy Vespa and Ingest Data

This launches a Vespa container with 8 GB memory, writes the Vespa app files to vespa_app_hybrid/, and streams FineWeb with on-the-fly embeddings.

python feed.py

Notes:

  • Dataset: HuggingFaceFW/fineweb split CC-MAIN-2025-08 (streaming).
  • Embeddings: all-MiniLM-L6-v2 (uses mps on Apple Silicon by default).
  • Stop with Ctrl+C once you have enough documents indexed.

Query Vespa via curl (BM25)

curl -X POST http://localhost:8080/search/ \
  -H "Content-Type: application/json" \
  -d '{
    "yql": "select * from sources * where userQuery() limit 10",
    "query": "python programming",
    "ranking": {"profile": "bm25"}
  }'

Run the UI (hybrid/semantic/BM25)

Start the FastAPI server:

uvicorn ui:app --reload

Open http://localhost:8000 and choose a ranking mode:

  • fusion: hybrid RRF over BM25 + ANN semantic scores
  • semantic: dense vector only
  • bm25: lexical only

Resources

About

How to build the best search, one step at a time!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published