retriever

package
v0.3.1-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 4 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 the call option for Retriever component.

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.

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 is the dsl info for the retriever, which is used to retrieve the documents from the retriever.
	// viking only
	DSLInfo map[string]interface{}
}

Options is the options for the retriever.

func GetCommonOptions

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

GetCommonOptions extract retriever Options from Option list, optionally providing a base Options with default values.

type Retriever

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

Retriever is the interface for retriever. It is used to retrieve documents from a source. there are `vectorstore` and `fornaxknowledge` can be used as retriever.

e.g.

	retriever, err := fornaxknowledge.NewRetriever(ctx, &RetrieverConfig{})
	if err != nil {...}
	docs, err := retriever.Retrieve(ctx, "query") // <= using directly
	docs, err := retriever.Retrieve(ctx, "query", retriever.WithTopK(3)) // <= using options

 	graph := compose.NewGraph[inputType, outputType](compose.RunTypeDAG)
	graph.AddRetrieverNode("retriever_node_key", retriever) // <= using in graph

Jump to

Keyboard shortcuts

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