Documentation
¶
Index ¶
- Constants
- type Chunker
- type Citation
- type DecayConfig
- type DeleteRequest
- type Document
- type DocumentEmbedding
- type HybridSearcher
- type IndexResult
- type Indexer
- type IndexerConfig
- type Loader
- type MMRConfig
- type MergeStrategy
- type MultiNamespaceOption
- type MultiNamespaceRetriever
- type PartialNamespaceError
- type Query
- type Reranker
- type SearchMode
- type SearchResult
- type TextSplitter
- type TextSplitterConfig
- type VectorStore
Constants ¶
const ( DefaultChunkMaxRunes = 1200 DefaultChunkOverlapRunes = 120 )
const DefaultIndexBatchSize = 32
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Citation ¶
type Citation struct {
ID string `json:"id"`
ParentID string `json:"parent_id,omitempty"`
Source string `json:"source,omitempty"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
ChunkIndex string `json:"chunk_index,omitempty"`
ChunkStart string `json:"chunk_start,omitempty"`
ChunkEnd string `json:"chunk_end,omitempty"`
}
func CitationFromDocument ¶
type DecayConfig ¶ added in v0.3.0
type DecayConfig struct {
// HalfLifeDays is the exponential half-life for decaying sources.
// Zero disables decay.
HalfLifeDays float64
// Now overrides the reference time (tests). Zero means time.Now().
Now time.Time
// EvergreenSources are metadata "source" values exempt from decay
// (default: global, workspace).
EvergreenSources []string
}
DecayConfig controls temporal score decay for session-like sources.
type DeleteRequest ¶
type DocumentEmbedding ¶
type HybridSearcher ¶
type HybridSearcher interface {
HybridQuery(ctx context.Context, query Query) ([]SearchResult, error)
}
type IndexResult ¶
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
func NewIndexer ¶
func NewIndexer(config IndexerConfig) (*Indexer, error)
type IndexerConfig ¶
type MMRConfig ¶ added in v0.3.0
type MMRConfig struct {
// Lambda balances relevance (1) vs diversity (0). Default 0.7.
Lambda float64
// Limit caps the returned list. Zero keeps all results.
Limit int
}
MMRConfig controls Maximal Marginal Relevance re-ranking.
type MergeStrategy ¶ added in v0.3.0
type MergeStrategy string
MergeStrategy controls how MultiNamespaceRetriever combines per-namespace hits.
const ( // MergeStrategyGlobalRank sorts all namespace hits by score (default). MergeStrategyGlobalRank MergeStrategy = "global_rank" // MergeStrategyBalanced interleaves results so each namespace contributes evenly. MergeStrategyBalanced MergeStrategy = "balanced" )
type MultiNamespaceOption ¶ added in v0.3.0
type MultiNamespaceOption func(*MultiNamespaceRetriever)
MultiNamespaceOption configures MultiNamespaceRetriever.
func WithAllowPartialNamespaces ¶ added in v0.3.0
func WithAllowPartialNamespaces() MultiNamespaceOption
WithAllowPartialNamespaces allows Query to return merged hits when some namespaces fail. Failures are still returned as a PartialNamespaceError so callers can observe them. Without this option, any namespace failure fails the whole Query (no silent skip).
func WithMergeStrategy ¶ added in v0.3.0
func WithMergeStrategy(strategy MergeStrategy) MultiNamespaceOption
WithMergeStrategy sets how results from multiple namespaces are merged.
type MultiNamespaceRetriever ¶ added in v0.3.0
type MultiNamespaceRetriever struct {
// contains filtered or unexported fields
}
MultiNamespaceRetriever fans a Query out across namespaces and merges hits.
func NewMultiNamespaceRetriever ¶ added in v0.3.0
func NewMultiNamespaceRetriever(store VectorStore, namespaces []string, opts ...MultiNamespaceOption) (*MultiNamespaceRetriever, error)
NewMultiNamespaceRetriever wraps store.Query with multi-namespace fan-out.
func (*MultiNamespaceRetriever) Query ¶ added in v0.3.0
func (r *MultiNamespaceRetriever) Query(ctx context.Context, query Query) ([]SearchResult, error)
Query runs the query against each configured namespace and merges results. By default any namespace failure fails the call. WithAllowPartialNamespaces returns merged hits plus a PartialNamespaceError when some namespaces fail.
type PartialNamespaceError ¶ added in v0.3.0
type PartialNamespaceError struct {
Failed []error
Results []SearchResult
}
PartialNamespaceError reports that one or more namespaces failed while others produced results. Callers that opt into WithAllowPartialNamespaces should use errors.As to detect it and decide whether to proceed with Results.
func (*PartialNamespaceError) Error ¶ added in v0.3.0
func (e *PartialNamespaceError) Error() string
func (*PartialNamespaceError) Unwrap ¶ added in v0.3.0
func (e *PartialNamespaceError) Unwrap() []error
type Query ¶
type Query struct {
Namespace string `json:"namespace,omitempty"`
Text string `json:"text,omitempty"`
Mode SearchMode `json:"mode,omitempty"`
Vector []float32 `json:"vector"`
Limit int `json:"limit,omitempty"`
Filter map[string]string `json:"filter,omitempty"`
VectorWeight float64 `json:"vector_weight,omitempty"`
TextWeight float64 `json:"text_weight,omitempty"`
}
type Reranker ¶
type Reranker interface {
Rerank(ctx context.Context, query string, results []SearchResult) ([]SearchResult, error)
}
type SearchMode ¶
type SearchMode string
const ( SearchModeVector SearchMode = "vector" SearchModeHybrid SearchMode = "hybrid" )
type SearchResult ¶
func ApplyMMR ¶ added in v0.3.0
func ApplyMMR(results []SearchResult, cfg MMRConfig) []SearchResult
ApplyMMR re-ranks results to reduce near-duplicate content while preserving high relevance. Similarity is a simple token Jaccard over document content (and document id when content is empty).
func ApplyTemporalDecay ¶ added in v0.3.0
func ApplyTemporalDecay(results []SearchResult, cfg DecayConfig) []SearchResult
ApplyTemporalDecay multiplies each result score by e^(-λ * age_days) for non-evergreen sources. Age is read from metadata keys created_at (unix seconds or RFC3339) or updated_at. Results without a parseable timestamp are left unchanged.
func MergeRRF ¶ added in v0.1.5
func MergeRRF(lists [][]SearchResult, k int, limit int) []SearchResult
MergeRRF fuses ranked result lists with reciprocal rank fusion.
type TextSplitter ¶
type TextSplitter struct {
// contains filtered or unexported fields
}
func NewTextSplitter ¶
func NewTextSplitter(config TextSplitterConfig) (*TextSplitter, error)
type TextSplitterConfig ¶
type VectorStore ¶
type VectorStore interface {
Upsert(ctx context.Context, documents []DocumentEmbedding) error
Query(ctx context.Context, query Query) ([]SearchResult, error)
Delete(ctx context.Context, req DeleteRequest) error
}