An API to generate Qdrant's BM42 sparse embeddings
1.5K
A FastAPI service for generating sparse text embeddings optimized for query relevance using the
Qdrant/bm42-all-minilm-l6-v2-attentions model.
This API provides endpoints for converting text into sparse vector representations (embeddings) that can be used for semantic search, document retrieval, and other NLP applications. It's particularly designed to handle long documents through a sliding window approach.
/embed (POST)Converts a batch of texts into sparse embeddings.
Request Body:
{
"texts": [
"your text here",
"another text"
],
"task": "query",
"sparsity_threshold": 0.005,
"allow_null_vector": false,
"window_size": 512,
"window_overlap": 100,
"window_combine_strategy": "max"
}
Parameters:
texts: List of texts to embedtask: Either "query" (for search queries) or "index" (for documents to be stored)sparsity_threshold: Filter out vector dimensions with values below this thresholdallow_null_vector: Whether to allow null vectors when all values are below thresholdwindow_size: Maximum token limit for each processing windowwindow_overlap: Overlap between adjacent windows in tokenswindow_combine_strategy: Strategy for combining window vectors ("max", "mean", "sum")Response:
Returns a list of sparse vectors in the format [indices, values] or null (if vector is filtered out).
/info (GET)Returns information about the API, including:
VERSION: API versionBUILD_ID: Build identifierCOMMIT_SHA: Git commit SHAPORT: Server port (default: 8000)uvicorn main:app --host 0.0.0.0 --port 8000
docker run -p 8000:8000 joanfabregat/bm42-embed:latest
For long texts exceeding the token limit, the API splits the text into overlapping windows, processes each window separately, and then combines the resulting embeddings using the specified strategy.
The API can filter out dimensions with small values to create sparser vectors, which can significantly reduce storage requirements while maintaining semantic quality.
This project is licensed under the MIT License - see the license notice in the code for details.
Developed by Joan Fabrégat, [email protected]
Content type
Image
Digest
sha256:d94b4331a…
Size
220.9 MB
Last updated
over 1 year ago
docker pull joanfabregat/bm42-embed