Skip to main content

llmatch-bm25

PyPI version License: MIT Downloads LinkedIn

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 default ChatLLM7 will be used.
  • api_key (Optional[str]): The API key for LLM7. If not provided, the package will use the default ChatLLM7 without 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

Metadata

Release files for llmatch-bm25 2025.12.21101341

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

Source distribution (sdist)

Source distribution for llmatch-bm25 2025.12.21101341
File Size Uploaded
llmatch_bm25-2025.12.21101341.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llmatch-bm25 2025.12.21101341
File Interpreter ABI Platform
llmatch_bm25-2025.12.21101341-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 kB

Release files / llmatch_bm25-2025.12.21101341.tar.gz

Download URL llmatch_bm25-2025.12.21101341.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5cce9a8add4fcf98237dd0b864395932c3d928f54948b0b1643e0238a23165a9
BLAKE2b-256 checksum
How to use checksums
37fb771bf9dc339c6a4106e3dcfa1e4d1a5c5246ff396db04124b27f8a4a917f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release files / llmatch_bm25-2025.12.21101341-py3-none-any.whl

Download URL llmatch_bm25-2025.12.21101341-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c0f03b25053a748decb96a39944ea45b02275b06eaca0f1b0df5b6db394b80e
BLAKE2b-256 checksum
How to use checksums
11bf110c1a18b826760529f0bccd5a3773bd8429815f4ebf33ca8a91ae747faf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

2025.12.21101341 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