Skip to main content

SparseEncoder

Trait SparseEncoder 

Source
pub trait SparseEncoder:
    Send
    + Sync
    + Debug {
    // Required methods
    fn model(&self) -> &str;
    fn vocab_id(&self) -> &str;
    fn encode(&self, text: &str) -> Result<SparseEmbed, SparseError>;

    // Provided method
    fn encode_query(&self, text: &str) -> Result<SparseEmbed, SparseError> { ... }
}
Expand description

Learned-sparse encoder: given text, produce a SparseEmbed over a fixed vocabulary. Adapter crates implement this over SPLADE-ONNX, BGE-M3-sparse-ONNX, or a remote sidecar.

Required Methods§

Source

fn model(&self) -> &str

Provider + model identifier. Lowercase, colon-separated by convention (e.g. "splade:opensearch-doc-v3-distill", "bgem3:sparse", "mock:len-inverse").

Source

fn vocab_id(&self) -> &str

Vocabulary identifier. Passed through to SparseEmbed::vocab_id on every emitted embedding.

Source

fn encode(&self, text: &str) -> Result<SparseEmbed, SparseError>

Encode a document-side text string into a sparse vector. This is the path run at ingest time.

§Errors

Any SparseError the adapter surfaces. The caller fallback policy matches the rerank / LLM pattern: on error, the sparse lane is simply dropped from fusion and the hybrid still runs.

Provided Methods§

Source

fn encode_query(&self, text: &str) -> Result<SparseEmbed, SparseError>

Encode a query-side text string into a sparse vector.

Default implementation delegates to Self::encode. Adapters with asymmetric inference (OpenSearch neural-sparse-encoding-doc-v3-distill ships a distilled idf.json table so the query side is tokenise + IDF-lookup with zero neural compute) override this to skip the forward pass. The overridden path keeps retrieval latency microsecond- level even when documents use a 67M-parameter encoder.

Implementors§