Documentation
¶
Index ¶
- Variables
- func ToRetriever(vectorStore VectorStore, numDocs int, options ...Option) schema.Retriever
- type ContextNetwork
- type DefinitionRetriever
- type DependencyRetriever
- type DocumentWithScore
- type HyDEOption
- type HyDERetriever
- type MultiQueryRetriever
- type Option
- func WithCollectionName(name string) Option
- func WithEmbedder(embedder embeddings.Embedder) Option
- func WithFilter(key string, value any) Option
- func WithFilters(filters map[string]any) Option
- func WithNameSpace(namespace string) Option
- func WithScoreThreshold(threshold float32) Option
- func WithSparseQueries(sparse []*schema.SparseVector) Option
- func WithSparseQuery(sparse *schema.SparseVector) Option
- type Options
- type RerankingRetriever
- type Retriever
- type ScoredRetriever
- type VectorStore
Constants ¶
This section is empty.
Variables ¶
var (
ErrCollectionNotFound = errors.New("collection not found")
)
Functions ¶
func ToRetriever ¶
func ToRetriever(vectorStore VectorStore, numDocs int, options ...Option) schema.Retriever
ToRetriever creates a retriever from a vector store.
Types ¶
type ContextNetwork ¶ added in v0.15.0
type ContextNetwork struct {
// Dependencies are documents that the current code imports/depends on
Dependencies []schema.Document
// Dependents are documents that import/depend on the current code (impact analysis)
Dependents []schema.Document
}
ContextNetwork represents the graph neighborhood of a piece of code
type DefinitionRetriever ¶ added in v0.15.0
type DefinitionRetriever struct {
// contains filtered or unexported fields
}
func NewDefinitionRetriever ¶ added in v0.15.0
func NewDefinitionRetriever(store VectorStore) *DefinitionRetriever
func (*DefinitionRetriever) GetDefinition ¶ added in v0.15.0
func (r *DefinitionRetriever) GetDefinition(ctx context.Context, symbolName string) ([]schema.Document, error)
GetDefinition looks up a symbol definition using hybrid search (dense + sparse). Filters by identifier and is_definition metadata for precise results.
type DependencyRetriever ¶ added in v0.15.0
type DependencyRetriever struct {
// contains filtered or unexported fields
}
DependencyRetriever optimizes RAG by traversing the dependency graph
func NewDependencyRetriever ¶ added in v0.15.0
func NewDependencyRetriever(store VectorStore) *DependencyRetriever
NewDependencyRetriever creates a new graph-based retriever
func (*DependencyRetriever) GetContextNetwork ¶ added in v0.15.0
func (r *DependencyRetriever) GetContextNetwork(ctx context.Context, packageName string, imports []string) (*ContextNetwork, error)
GetContextNetwork retrieves both upstream dependencies and downstream impact
type DocumentWithScore ¶
type HyDEOption ¶ added in v0.15.0
type HyDEOption func(*HyDERetriever)
func WithNumGenerations ¶ added in v0.15.0
func WithNumGenerations(n int) HyDEOption
WithNumGenerations sets how many hypothetical documents to generate.
type HyDERetriever ¶ added in v0.15.0
type HyDERetriever struct {
// BaseRetriever performs the actual similarity search
BaseRetriever schema.Retriever
// Generator produces a hypothetical document from a query
Generator func(ctx context.Context, query string) (string, error)
// NumGenerations controls how many hypothetical docs to generate (default 1).
// When > 1, results from all generated docs are deduplicated.
NumGenerations int
}
HyDERetriever implements the Hypothetical Document Embedding pattern. It asks an LLM to generate a hypothetical answer to the query, then uses that hypothetical answer as the search query against the base retriever. This often finds better matches because the hypothetical answer is closer in embedding space to the actual stored documents.
func NewHyDERetriever ¶ added in v0.15.0
func NewHyDERetriever(baseRetriever schema.Retriever, generator func(ctx context.Context, query string) (string, error), opts ...HyDEOption) *HyDERetriever
func (*HyDERetriever) GetRelevantDocuments ¶ added in v0.15.0
type MultiQueryRetriever ¶ added in v0.15.0
type MultiQueryRetriever struct {
Store VectorStore
LLM llms.Model
NumDocuments int
Count int
// Max results to return after deduplication across all query variations.
// Defaults to NumDocuments when zero.
MaxResults int
// Hook to generate sparse vectors for the newly generated queries
SparseGenFunc func(ctx context.Context, queries []string) ([]*schema.SparseVector, error)
}
func (MultiQueryRetriever) GetRelevantDocuments ¶ added in v0.15.0
type Option ¶
type Option func(*Options)
func WithCollectionName ¶ added in v0.7.1
WithCollectionName sets the collection name for the Qdrant store.
func WithEmbedder ¶
func WithEmbedder(embedder embeddings.Embedder) Option
func WithFilter ¶
func WithFilters ¶
func WithNameSpace ¶
func WithScoreThreshold ¶
func WithSparseQueries ¶ added in v0.15.0
func WithSparseQueries(sparse []*schema.SparseVector) Option
func WithSparseQuery ¶ added in v0.15.0
func WithSparseQuery(sparse *schema.SparseVector) Option
type Options ¶
type Options struct {
Embedder embeddings.Embedder
NameSpace string
CollectionName string
ScoreThreshold float32
Filters map[string]any
SparseQuery *schema.SparseVector
SparseQueries []*schema.SparseVector
}
func ParseOptions ¶
type RerankingRetriever ¶ added in v0.15.0
type RerankingRetriever struct {
Retriever schema.Retriever
Reranker schema.Reranker
TopK int // Final number of documents to return after reranking
// Pre-filter candidates before sending to the reranker. Useful for cheap
// filtering (e.g. BM25 scoring) to reduce the number of documents the
// expensive LLM-based reranker has to process.
CandidateFilter func(query string, docs []schema.Document) []schema.Document
// MinScore filters out documents that have a reranked score below this threshold.
// If zero, no threshold is applied.
MinScore float32
}
RerankingRetriever wraps a standard retriever and uses a reranker to refine results.
func (RerankingRetriever) GetRelevantDocuments ¶ added in v0.15.0
func (RerankingRetriever) GetRelevantScoredDocuments ¶ added in v0.15.0
func (r RerankingRetriever) GetRelevantScoredDocuments(ctx context.Context, query string) ([]schema.ScoredDocument, error)
type Retriever ¶
type Retriever interface {
GetRelevantDocuments(ctx context.Context, query string) ([]schema.Document, error)
}
Retriever is the interface for fetching relevant documents for a query.
type ScoredRetriever ¶ added in v0.15.0
type ScoredRetriever interface {
GetRelevantScoredDocuments(ctx context.Context, query string) ([]schema.ScoredDocument, error)
}
ScoredRetriever is a retriever that returns documents with relevance scores.
type VectorStore ¶
type VectorStore interface {
AddDocuments(ctx context.Context, docs []schema.Document, options ...Option) ([]string, error)
SimilaritySearch(ctx context.Context, query string, numDocuments int, options ...Option) ([]schema.Document, error)
SimilaritySearchBatch(ctx context.Context, queries []string, numDocuments int, options ...Option) ([][]schema.Document, error)
SimilaritySearchWithScores(ctx context.Context, query string, numDocuments int, options ...Option) ([]DocumentWithScore, error)
ListCollections(ctx context.Context) ([]string, error)
DeleteCollection(ctx context.Context, collectionName string) error
DeleteDocumentsByFilter(ctx context.Context, filters map[string]any, options ...Option) error
}