The new package transforms a user’s plain‑text search phrase into a structured, BM25‑ranked list of PostgreSQL search results. It takes the query text as input, forwards it to an LLM that rewrites the
Project description
llmatch-bm25
A Python package that transforms a user's plain-text search phrase into a structured, BM25-ranked list of PostgreSQL search results.
Features
- Transforms user input into BM25-friendly format using an LLM
- Runs the query against the database
- Returns a JSON array of hits with title, snippet, and BM25 relevance score
- Ensures LLM output matches expected JSON pattern with retries and diagnostics
- Quick and reliable way to embed BM25-based relevance into database-query workflows
Installation
pip install llmatch_bm25
Usage
Basic Usage
from llmatch_bm25 import llmatch_bm25
response = llmatch_bm25(user_input="your search query here")
Using a Custom LLM
You can use any LLM compatible with LangChain's BaseChatModel interface. Here are examples with different LLMs:
Using OpenAI
from langchain_openai import ChatOpenAI
from llmatch_bm25 import llmatch_bm25
llm = ChatOpenAI()
response = llmatch_bm25(user_input="your search query here", llm=llm)
Using Anthropic
from langchain_anthropic import ChatAnthropic
from llmatch_bm25 import llmatch_bm25
llm = ChatAnthropic()
response = llmatch_bm25(user_input="your search query here", llm=llm)
Using Google
from langchain_google_genai import ChatGoogleGenerativeAI
from llmatch_bm25 import llmatch_bm25
llm = ChatGoogleGenerativeAI()
response = llmatch_bm25(user_input="your search query here", llm=llm)
Using LLM7 API Key
By default, the package uses the ChatLLM7 from langchain_llm7. You can pass your own API key via an environment variable or directly in the function call.
Using Environment Variable
import os
from llmatch_bm25 import llmatch_bm25
os.environ["LLM7_API_KEY"] = "your_api_key_here"
response = llmatch_bm25(user_input="your search query here")
Directly Passing API Key
from llmatch_bm25 import llmatch_bm25
response = llmatch_bm25(user_input="your search query here", api_key="your_api_key_here")
Parameters
user_input(str): The user input text to process.llm(Optional[BaseChatModel]): The LangChain LLM instance to use. If not provided, the defaultChatLLM7will be used.api_key(Optional[str]): The API key for LLM7. If not provided, the package will use the defaultChatLLM7without an API key.
Rate Limits
The default rate limits for LLM7 free tier are sufficient for most use cases of this package. If you want higher rate limits, you can pass your own API key via the environment variable LLM7_API_KEY or directly in the function call.
Getting an API Key
You can get a free API key by registering at LLM7.
Issues
If you encounter any issues, please report them on the GitHub issues page.
Author
- Eugene Evstafev
- Email: hi@eugene.plus
- GitHub: chigwell
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llmatch_bm25-2025.12.21101341.tar.gz.
File metadata
- Download URL: llmatch_bm25-2025.12.21101341.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cce9a8add4fcf98237dd0b864395932c3d928f54948b0b1643e0238a23165a9
|
|
| MD5 |
49c9192b3f2095149f496227aa153d82
|
|
| BLAKE2b-256 |
37fb771bf9dc339c6a4106e3dcfa1e4d1a5c5246ff396db04124b27f8a4a917f
|
File details
Details for the file llmatch_bm25-2025.12.21101341-py3-none-any.whl.
File metadata
- Download URL: llmatch_bm25-2025.12.21101341-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c0f03b25053a748decb96a39944ea45b02275b06eaca0f1b0df5b6db394b80e
|
|
| MD5 |
f686b30e5d2f04e9a586aeb3b883418c
|
|
| BLAKE2b-256 |
11bf110c1a18b826760529f0bccd5a3773bd8429815f4ebf33ca8a91ae747faf
|