Skip to main content
Version: 0.0.4

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:

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 IDF weighting is applied by the sparse index at query time instead. Implementations with no such asymmetry may 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.