Skip to main content

RAG Search

A hybrid retrieval component for Retrieval-Augmented Generation (RAG) pipelines.

RAG Search combines lexical retrieval and semantic vector retrieval, fuses their results using Reciprocal Rank Fusion (RRF), and applies a CrossEncoder reranker to produce a final ranked set of documents.

The package works with LangChain Document objects and is designed as a modular retrieval component that can be used independently or as part of a larger RAG pipeline.

Features

  • BM25 lexical retrieval
  • Vector-based semantic retrieval
  • Local Chroma vector store
  • Configurable embedding model
  • Reciprocal Rank Fusion (RRF)
  • CrossEncoder reranking
  • Parallel BM25 and vector retrieval
  • Configurable result count
  • Configurable RRF rank constant
  • Configurable reranker
  • Support for custom BM25 and vector retrievers

Retrieval Pipeline

The retrieval process follows this flow:

                         Query
                           │
              ┌────────────┴────────────┐
              │                         │
              ▼                         ▼
        BM25 Retrieval          Vector Retrieval
              │                         │
              └────────────┬────────────┘
                           ▼
                Reciprocal Rank Fusion
                           │
                           ▼
                    CrossEncoder
                     Reranking
                           │
                           ▼
                    Top-K Results

BM25 provides lexical matching, while vector retrieval provides semantic matching. Their results are combined using Reciprocal Rank Fusion before the final CrossEncoder reranking stage.

Installation

pip install rag-search-kit

Basic Usage

from rag_search import RAGSearch

search = RAGSearch(documents)

results = search.search(
    "What is artificial intelligence?",
    top_k=5,
)

documents should be a sequence of LangChain Document objects.

The search() method returns a list of ranked Document objects.

BM25 Retriever

The package provides a standalone BM25 retriever:

from rag_search import BM25Retriever

retriever = BM25Retriever(
    documents,
    top_k=5,
)

results = retriever.retrieve(
    "What is artificial intelligence?"
)

The BM25 retriever performs lexical matching using tokenized document text.

Vector Retriever

The package also provides a standalone vector retriever:

from rag_search import VectorRetriever

retriever = VectorRetriever(
    documents,
    top_k=5,
)

results = retriever.retrieve(
    "What is artificial intelligence?"
)

By default, the vector retriever uses:

sentence-transformers/all-MiniLM-L6-v2

and stores the document embeddings in a local Chroma vector store.

A custom LangChain-compatible embedding model can also be supplied:

retriever = VectorRetriever(
    documents,
    embedding_model=custom_embedding_model,
)

The RAGSearch class combines both retrieval approaches:

from rag_search import RAGSearch

search = RAGSearch(documents)

results = search.search(
    "What is artificial intelligence?",
    top_k=5,
)

Internally, BM25 and vector retrieval are executed concurrently. Their ranked results are then combined using Reciprocal Rank Fusion (RRF), followed by CrossEncoder reranking.

Configuration

Result Count

The default retrieval limit is 5.

search = RAGSearch(documents)

results = search.search(
    "What is artificial intelligence?",
    top_k=10,
)

RRF Rank Constant

The default RRF rank constant is 60.

search = RAGSearch(
    documents,
    rank_constant=60,
)

Reranker

The default CrossEncoder reranker is:

BAAI/bge-reranker-v2-m3

A different CrossEncoder model can be supplied:

search = RAGSearch(
    documents,
    reranker="your-reranker-model",
)

Custom Retrievers

RAGSearch also allows custom BM25 and vector retriever instances:

search = RAGSearch(
    documents,
    bm25_retriever=custom_bm25,
    vector_retriever=custom_vector,
)

This allows the hybrid search layer to be composed with customized retrieval implementations.

Components

The package exposes three main components:

Component Purpose
BM25Retriever Lexical retrieval
VectorRetriever Semantic vector retrieval
RAGSearch Hybrid retrieval, RRF fusion, and reranking

Dependencies

The retrieval implementation uses components from the LangChain ecosystem together with:

  • Chroma
  • Hugging Face embeddings
  • BM25
  • Ranx for Reciprocal Rank Fusion
  • Sentence Transformers for CrossEncoder reranking

Package dependencies are defined in pyproject.toml.

Role in a RAG Pipeline

RAG Search is intended to operate after document ingestion and chunking:

Documents
    ↓
Document Ingestion
    ↓
Cleaning & Chunking
    ↓
RAG Search
    ↓
Retrieved Context
    ↓
LLM

It focuses specifically on retrieval and ranking. Document loading and chunking are handled separately.

Status

This is the initial version of the RAG Search component, developed as a modular retrieval building block for a larger RAG system.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Release files for rag-search-kit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rag-search-kit 0.1.0
File Size Uploaded
rag_search_kit-0.1.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rag-search-kit 0.1.0
File Interpreter ABI Platform
rag_search_kit-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / rag_search_kit-0.1.0.tar.gz

Download URL rag_search_kit-0.1.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
38ae45f1a7686219f845aaab9e1dc9e84deaab23eb7caa7920b7812db2a6c36a
BLAKE2b-256 checksum
How to use checksums
519747c954c1f1e00d2e76073d03de297ce0da6da0cb7455c5ff5c262d60aaab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / rag_search_kit-0.1.0-py3-none-any.whl

Download URL rag_search_kit-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c01a9f56cb0a36b145a404834154f441fb0cb944eecd5b888ec17743e33ffe6e
BLAKE2b-256 checksum
How to use checksums
5cf6be4aa335815af23deb255189595051476a118f89ae7d6614dc314ea768eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page