knowledge

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultChunkMaxRunes     = 1200
	DefaultChunkOverlapRunes = 120
)
View Source
const DefaultIndexBatchSize = 32

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunker

type Chunker interface {
	Split(document Document) ([]Document, error)
}

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

func CitationFromDocument(document Document) Citation

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 DeleteRequest struct {
	Namespace string `json:"namespace,omitempty"`
	ID        string `json:"id"`
}

type Document

type Document struct {
	ID        string            `json:"id"`
	Content   string            `json:"content"`
	Metadata  map[string]string `json:"metadata,omitempty"`
	Namespace string            `json:"namespace,omitempty"`
}

type DocumentEmbedding

type DocumentEmbedding struct {
	Document Document  `json:"document"`
	Vector   []float32 `json:"vector"`
}

type HybridSearcher

type HybridSearcher interface {
	HybridQuery(ctx context.Context, query Query) ([]SearchResult, error)
}

type IndexResult

type IndexResult struct {
	Documents int `json:"documents"`
	Chunks    int `json:"chunks"`
}

type Indexer

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

func NewIndexer

func NewIndexer(config IndexerConfig) (*Indexer, error)

func (*Indexer) Index

func (i *Indexer) Index(ctx context.Context, documents []Document) (IndexResult, error)

type IndexerConfig

type IndexerConfig struct {
	Embedder  llm.Embedder
	Store     VectorStore
	Profile   string
	Namespace string
	BatchSize int
	Chunker   Chunker
}

type Loader

type Loader interface {
	Load(ctx context.Context) ([]Document, error)
}

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

type SearchResult struct {
	Document Document `json:"document"`
	Score    float64  `json:"score"`
}

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)

func (*TextSplitter) Split

func (s *TextSplitter) Split(document Document) ([]Document, error)

type TextSplitterConfig

type TextSplitterConfig struct {
	MaxRunes     int
	OverlapRunes int
}

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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