search

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package search provides search implementations for gognee's knowledge graph.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSeeds = errors.New("graph search requires seed node IDs in SearchOptions.SeedNodeIDs")

ErrNoSeeds is returned when graph search is attempted without seed nodes.

Functions

func ApplyDefaults

func ApplyDefaults(opts *SearchOptions)

ApplyDefaults sets default values for unspecified search options.

Types

type DecayingSearcher

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

DecayingSearcher is a decorator that applies time-based decay to search results. It wraps any Searcher implementation and modifies scores based on node age.

func NewDecayingSearcher

func NewDecayingSearcher(
	underlying Searcher,
	graphStore store.GraphStore,
	memoryStore store.MemoryStore,
	enabled bool,
	halfLifeDays int,
	basis string,
	accessFrequencyEnabled bool,
	referenceAccessCount int,
) *DecayingSearcher

NewDecayingSearcher creates a new decaying searcher wrapper.

Parameters:

  • underlying: The base searcher to wrap
  • graphStore: Graph store for retrieving node timestamps
  • memoryStore: Memory store for retrieving access counts (M2: Plan 021)
  • enabled: Whether decay is enabled
  • halfLifeDays: Number of days for half-life decay
  • basis: "access" (use last_accessed_at) or "creation" (use created_at)
  • accessFrequencyEnabled: Whether to apply access frequency heat multiplier (M2: Plan 021)
  • referenceAccessCount: Reference count for full heat protection (M2: Plan 021)

func (*DecayingSearcher) Search

func (d *DecayingSearcher) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)

Search performs search with decay applied to scores.

func (*DecayingSearcher) SetLogger added in v1.6.0

func (d *DecayingSearcher) SetLogger(logger *slog.Logger)

SetLogger sets the structured logger for this DecayingSearcher (M8: Plan 023). When nil, logging is disabled (zero overhead).

type GraphSearcher

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

GraphSearcher performs graph traversal search from seed nodes.

func NewGraphSearcher

func NewGraphSearcher(graphStore store.GraphStore) *GraphSearcher

NewGraphSearcher creates a new graph searcher.

func (*GraphSearcher) Search

func (g *GraphSearcher) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)

Search performs graph traversal from seed nodes. The query parameter is ignored (graph search uses opts.SeedNodeIDs).

type HybridSearcher

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

HybridSearcher combines vector similarity and graph traversal search.

func NewHybridSearcher

func NewHybridSearcher(
	embClient embeddings.EmbeddingClient,
	vectorStore store.VectorStore,
	graphStore store.GraphStore,
) *HybridSearcher

NewHybridSearcher creates a new hybrid searcher.

func (*HybridSearcher) Search

func (h *HybridSearcher) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)

Search performs hybrid search combining vector similarity and graph expansion. Score formula: combined_score = vector_score + graph_score where vector_score = 0 if not found by vector, graph_score = 0 if not found by graph.

type SearchOptions

type SearchOptions struct {
	Type       SearchType // Type of search to perform
	TopK       int        // Maximum number of results to return (default: 10)
	GraphDepth int        // Maximum graph traversal depth (default: 1)
	// SeedNodeIDs specifies starting nodes for graph search.
	// Required for SearchTypeGraph; ignored for SearchTypeVector.
	// For SearchTypeHybrid, seeds augment vector results.
	SeedNodeIDs []string
	// IncludeMemoryIDs enables memory provenance enrichment (v1.0.0+).
	// Default: true. Set to false to skip provenance lookup for performance.
	IncludeMemoryIDs *bool
	// TraceEnabled enables detailed timing instrumentation for performance analysis.
	// Default: false (off by default to minimize overhead).
	TraceEnabled bool
}

SearchOptions configures search behavior.

type SearchResult

type SearchResult struct {
	NodeID string      // Unique identifier of the node
	Node   *store.Node // Full node data (nil if node was deleted)
	Score  float64     // Combined relevance score (higher is better)
	Source string      // Origin: "vector", "graph", or "hybrid"
	// GraphDepth indicates the minimum graph distance from the search origin.
	// 0 for direct vector hits, >0 for nodes discovered via graph expansion.
	GraphDepth int
	// MemoryIDs lists memory IDs that reference this node (v1.0.0+).
	// Sorted by memory updated_at DESC (most recent first).
	// Empty for legacy nodes (created via Add/Cognify without provenance).
	MemoryIDs []string
}

SearchResult represents a single search result with scoring metadata.

type SearchType

type SearchType string

SearchType specifies the type of search to perform.

const (
	// SearchTypeVector performs vector similarity search only.
	SearchTypeVector SearchType = "vector"

	// SearchTypeGraph performs graph traversal search only (requires seed nodes).
	SearchTypeGraph SearchType = "graph"

	// SearchTypeHybrid combines vector similarity and graph traversal.
	SearchTypeHybrid SearchType = "hybrid"
)

type Searcher

type Searcher interface {
	// Search performs a search based on the query and options.
	// For vector/hybrid search, query is the text to embed and search.
	// For graph search, query is ignored (uses opts.SeedNodeIDs instead).
	Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)
}

Searcher defines the interface for knowledge graph search.

type VectorSearcher

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

VectorSearcher performs vector similarity search.

func NewVectorSearcher

func NewVectorSearcher(
	embClient embeddings.EmbeddingClient,
	vectorStore store.VectorStore,
	graphStore store.GraphStore,
) *VectorSearcher

NewVectorSearcher creates a new vector searcher.

func (*VectorSearcher) Search

func (v *VectorSearcher) Search(ctx context.Context, query string, opts SearchOptions) ([]SearchResult, error)

Search performs vector similarity search. It embeds the query, searches the vector store, and enriches results with full node data.

Jump to

Keyboard shortcuts

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