MCPcopy Index your code
hub / github.com/AmenRa/retriv

github.com/AmenRa/retriv @v0.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.1 ↗ · + Follow
228 symbols 769 edges 40 files 43 documented · 19%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

PyPI version

License: MIT

🔥 News

  • [February 18, 2023] retriv 0.2.0 is out!
    This release adds support for Dense and Hybrid Retrieval. Dense Retrieval leverages the semantic similarity of the queries' and documents' vector representations, which can be computed directly by retriv or imported from other sources. Hybrid Retrieval mix traditional retrieval, informally called Sparse Retrieval, and Dense Retrieval results to further improve retrieval effectiveness. As the library was almost completely redone, indices built with previous versions are no longer supported.

⚡️ Introduction

retriv is a user-friendly and efficient search engine implemented in Python supporting Sparse (traditional search with BM25, TF-IDF), Dense (semantic search) and Hybrid retrieval (a mix of Sparse and Dense Retrieval). It allows you to build a search engine in a single line of code.

retriv is built upon Numba for high-speed vector operations and automatic parallelization, PyTorch and Transformers for easy access and usage of Transformer-based Language Models, and Faiss for approximate nearest neighbor search. In addition, it provides automatic tuning functionalities to allow you to tune its internal components with minimal intervention.

✨ Main Features

Retrievers

Unified Search Interface

All the supported retrievers share the same search interface: - search: standard search functionality, what you expect by a search engine. - msearch: computes the results for multiple queries at once. It leverages automatic parallelization whenever possible. - bsearch: similar to msearch but automatically generates batches of queries to evaluate and allows dynamic writing of the search results to disk in JSONl format. bsearch is handy for computing results for hundreds of thousands or even millions of queries without hogging your RAM. Pre-computed results can be leveraged for negative sampling during the training of Neural Models for Information Retrieval.

AutoTune

retriv automatically tunes Faiss configuration for approximate nearest neighbors search by leveraging AutoFaiss to guarantee 10ms response time based on your available hardware. Moreover, it offers an automatic tuning functionality for BM25's parameters, which require minimal user intervention. Under the hood, retriv leverages Optuna, a hyperparameter optimization framework, and ranx, an Information Retrieval evaluation library, to test several parameter configurations for BM25 and choose the best one. Finally, it can automatically balance the importance of lexical and semantic relevance scores computed by the Hybrid Retriever to maximize retrieval effectiveness.

📚 Documentation

🔌 Requirements

python>=3.8

💾 Installation

pip install retriv

💡 Minimal Working Example

# Note: SearchEngine is an alias for the SparseRetriever
from retriv import SearchEngine

collection = [
  {"id": "doc_1", "text": "Generals gathered in their masses"},
  {"id": "doc_2", "text": "Just like witches at black masses"},
  {"id": "doc_3", "text": "Evil minds that plot destruction"},
  {"id": "doc_4", "text": "Sorcerer of death's construction"},
]

se = SearchEngine("new-index").index(collection)

se.search("witches masses")

Output:

[
  {
    "id": "doc_2",
    "text": "Just like witches at black masses",
    "score": 1.7536403
  },
  {
    "id": "doc_1",
    "text": "Generals gathered in their masses",
    "score": 0.6931472
  }
]

🎁 Feature Requests

Would you like to see other features implemented? Please, open a feature request.

🤘 Want to contribute?

Would you like to contribute? Please, drop me an e-mail.

📄 License

retriv is an open-sourced software licensed under the MIT license.

Core symbols most depended-on inside this repo

get_stopwords
called by 13
retriv/sparse_retriever/preprocessing/stopwords.py
index_path
called by 11
retriv/paths.py
get_stemmer
called by 7
retriv/sparse_retriever/preprocessing/stemmer.py
get_tokenizer
called by 7
retriv/sparse_retriever/preprocessing/tokenizer.py
extract_scores
called by 7
retriv/merger/normalization.py
min_max_norm
called by 7
retriv/merger/normalization.py
initialize_doc_index
called by 6
retriv/base_retriever.py
docs_path
called by 5
retriv/paths.py

Shape

Function 150
Method 71
Class 7

Languages

Python100%

Modules by API surface

retriv/sparse_retriever/preprocessing/stemmer.py34 symbols
retriv/base_retriever.py18 symbols
retriv/sparse_retriever/sparse_retriever.py14 symbols
retriv/dense_retriever/dense_retriever.py14 symbols
retriv/paths.py13 symbols
retriv/dense_retriever/encoder.py13 symbols
tests/merger/score_normalization_test.py11 symbols
retriv/hybrid_retriever.py10 symbols
retriv/merger/normalization.py9 symbols
tests/sparse_retriever/stopwords_test.py8 symbols
retriv/sparse_retriever/preprocessing/normalization.py7 symbols
retriv/merger/merger.py7 symbols

For agents

$ claude mcp add retriv \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact