agrag.embedding.sparse_base.SparseEmbedder
Bases: ABC
A component that turns text into sparse lexical vectors, for hybrid search.
Functions:
- embed – Embed a batch of documents into sparse vectors.
- query_embed – Embed a batch of search queries into sparse vectors.
Attributes:
- model (
str) –
embed
embed(texts:Sequence[str]) -> list[SparseVector]
Embed a batch of documents into sparse vectors.
Parameters:
- texts (
Sequence[str]) – The document texts to embed, in order.
Returns:
list[SparseVector]– One sparse vector per input text, in the same order.
model
model: str
query_embed
query_embed(texts:Sequence[str]) -> list[SparseVector]
Embed a batch of search queries into sparse vectors.
Query-side sparse embedding is not always the same computation as
document-side embedding. BM25, for example, applies term-frequency
and document-length normalization on the document side but only a
uniform per-term weight on the query side, since the sparse index
applies IDF weighting at query time instead. Implementations
with no such asymmetry can implement this identically to embed.
Parameters:
- texts (
Sequence[str]) – The query texts to embed, in order.
Returns:
list[SparseVector]– One sparse vector per input text, in the same order.