retriever

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 54

Documentation

Overview

Package retriever defines the Retriever component interface for fetching relevant documents from a document store given a query.

Overview

A Retriever is the read path of a RAG (Retrieval-Augmented Generation) pipeline. Given a query string it returns the most relevant schema.Document values from an underlying store (vector DB, keyword index, etc.).

Concrete implementations (VikingDB, Milvus, Elasticsearch, …) live in eino-ext:

github.com/cloudwego/eino-ext/components/retriever/

Relationship to Indexer

[Indexer] and Retriever are complementary:

  • Indexer writes documents (and their vectors) to the store
  • Retriever reads them back

When both use an embedding.Embedder, it must be the same model — vector dimensions must match or similarity scores will be meaningless.

Result Ordering

Results are ordered by relevance score (descending). Scores and other backend metadata are available via schema.Document.MetaData.

See https://www.cloudwego.io/docs/eino/core_modules/components/retriever_guide/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImplSpecificOptions added in v0.3.6

func GetImplSpecificOptions[T any](base *T, opts ...Option) *T

GetImplSpecificOptions extracts implementation-specific options from opts, merging onto base. Call alongside GetCommonOptions inside Retrieve.

Types

type CallbackInput

type CallbackInput struct {
	// Query is the query for the retriever.
	Query string

	// TopK is the top k for the retriever, which means the top number of documents to retrieve.
	TopK int
	// Filter is the filter for the retriever.
	Filter string
	// ScoreThreshold is the score threshold for the retriever, eg 0.5 means the score of the document must be greater than 0.5.
	ScoreThreshold *float64

	// Extra is the extra information for the retriever.
	Extra map[string]any
}

CallbackInput is the input for the retriever callback.

func ConvCallbackInput

func ConvCallbackInput(src callbacks.CallbackInput) *CallbackInput

ConvCallbackInput converts the callback input to the retriever callback input.

type CallbackOutput

type CallbackOutput struct {
	// Docs is the documents for the retriever.
	Docs []*schema.Document
	// Extra is the extra information for the retriever.
	Extra map[string]any
}

CallbackOutput is the output for the retriever callback.

func ConvCallbackOutput

func ConvCallbackOutput(src callbacks.CallbackOutput) *CallbackOutput

ConvCallbackOutput converts the callback output to the retriever callback output.

type Option

type Option struct {
	// contains filtered or unexported fields
}

Option is a call-time option for a Retriever.

func WithDSLInfo

func WithDSLInfo(dsl map[string]any) Option

WithDSLInfo wraps the dsl info option.

func WithEmbedding

func WithEmbedding(emb embedding.Embedder) Option

WithEmbedding wraps the embedder option.

func WithIndex

func WithIndex(index string) Option

WithIndex wraps the index option.

func WithScoreThreshold

func WithScoreThreshold(threshold float64) Option

WithScoreThreshold wraps the score threshold option.

func WithSubIndex

func WithSubIndex(subIndex string) Option

WithSubIndex wraps the sub index option.

func WithTopK

func WithTopK(topK int) Option

WithTopK wraps the top k option.

func WrapImplSpecificOptFn added in v0.3.6

func WrapImplSpecificOptFn[T any](optFn func(*T)) Option

WrapImplSpecificOptFn wraps an implementation-specific option function so it can be passed alongside standard options. For use by Retriever implementors.

type Options

type Options struct {
	// Index is the index for the retriever, index in different retriever may be different.
	Index *string
	// SubIndex is the sub index for the retriever, sub index in different retriever may be different.
	SubIndex *string
	// TopK is the top k for the retriever, which means the top number of documents to retrieve.
	TopK *int
	// ScoreThreshold is the score threshold for the retriever, eg 0.5 means the score of the document must be greater than 0.5.
	ScoreThreshold *float64
	// Embedding is the embedder for the retriever, which is used to embed the query for retrieval	.
	Embedding embedding.Embedder

	// DSLInfo carries backend-specific filter/query expressions. The structure and
	// semantics are defined by the underlying store implementation.
	DSLInfo map[string]any
}

Options is the options for the retriever.

func GetCommonOptions

func GetCommonOptions(base *Options, opts ...Option) *Options

GetCommonOptions extracts standard Options from opts, merging onto base. Implementors must call this to honour caller-provided options:

func (r *MyRetriever) Retrieve(ctx context.Context, query string, opts ...retriever.Option) ([]*schema.Document, error) {
    options := retriever.GetCommonOptions(&retriever.Options{TopK: &r.defaultTopK}, opts...)
    // use options.TopK, options.ScoreThreshold, options.Embedding, etc.
}

type Retriever

type Retriever interface {
	Retrieve(ctx context.Context, query string, opts ...Option) ([]*schema.Document, error)
}

Retriever fetches the most relevant documents from a store for a given query.

Retrieve accepts a natural-language query string and returns matching schema.Document values ordered by relevance (most relevant first). Relevance scores and backend-specific metadata are available in schema.Document.MetaData.

When [Options.Embedding] is set, the implementation converts the query to a vector before searching. The embedder must be the same model used at index time — see [indexer.Options.Embedding].

[Options.ScoreThreshold] is a filter, not a sort: documents scoring below the threshold are excluded entirely. [Options.TopK] caps the number of results returned.

Retrieve can be used standalone or added to a Graph via AddRetrieverNode:

retriever, _ := redis.NewRetriever(ctx, cfg)
docs, _ := retriever.Retrieve(ctx, "what is eino?", retriever.WithTopK(5))

graph.AddRetrieverNode("retriever", retriever)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL