Documentation
¶
Index ¶
- Constants
- func BuildTools(gs Store) []*agent.Tool
- type BoltStore
- func (s *BoltStore) AddTriple(_ context.Context, t Triple) error
- func (s *BoltStore) AddTriples(_ context.Context, triples []Triple) error
- func (s *BoltStore) AllTriples(_ context.Context) ([]Triple, error)
- func (s *BoltStore) ClearAll(_ context.Context) error
- func (s *BoltStore) Close() error
- func (s *BoltStore) Count(_ context.Context) (int, error)
- func (s *BoltStore) PredicateStats(_ context.Context) (map[string]int, error)
- func (s *BoltStore) QueryByObject(_ context.Context, object string) ([]Triple, error)
- func (s *BoltStore) QueryBySubject(_ context.Context, subject string) ([]Triple, error)
- func (s *BoltStore) QueryBySubjectPredicate(_ context.Context, subject, predicate string) ([]Triple, error)
- func (s *BoltStore) RemoveTriple(_ context.Context, t Triple) error
- func (s *BoltStore) SetPredicateValidator(v PredicateValidatorFunc)
- func (s *BoltStore) Traverse(_ context.Context, startNode string, maxDepth int, predicates []string) ([]Triple, error)
- type Extractor
- type ExtractorOption
- type GraphBuffer
- type GraphNode
- type GraphRAGResult
- type GraphRAGService
- type GraphRequest
- type Predicate
- type PredicateValidatorFunc
- type Store
- type Triple
- type VectorResult
- type VectorRetrieveOptions
- type VectorRetriever
Constants ¶
const ( RelatedTo = "related_to" // semantic relationship between entities CausedBy = "caused_by" // causal relationship (effect → cause) ResolvedBy = "resolved_by" // resolution relationship (error → fix) Follows = "follows" // temporal ordering (observation → observation) SimilarTo = "similar_to" // similarity relationship (learning ↔ learning) Contains = "contains" // containment (session → observation) InSession = "in_session" // session membership ReflectsOn = "reflects_on" // reflection targets (reflection → observation) LearnedFrom = "learned_from" // provenance (learning → session) )
Predicate constants define relationship types in the knowledge graph. These are untyped string constants to allow direct use in Triple struct literals where the Predicate field is string. Use Predicate(x).Valid() for validation.
Variables ¶
This section is empty.
Functions ¶
func BuildTools ¶ added in v0.7.0
BuildTools creates tools for graph traversal and querying.
Types ¶
type BoltStore ¶
type BoltStore struct {
// contains filtered or unexported fields
}
BoltStore is a BoltDB-backed triple store with SPO, POS, and OSP indexes.
func NewBoltStore ¶
NewBoltStore opens (or creates) a BoltDB database at path and initialises the three index buckets.
func (*BoltStore) AddTriples ¶
AddTriples adds multiple triples in a single atomic transaction.
func (*BoltStore) AllTriples ¶ added in v0.4.0
AllTriples returns every triple stored in the SPO index.
func (*BoltStore) Count ¶
Count returns the total number of triples by counting keys in the SPO bucket.
func (*BoltStore) PredicateStats ¶
PredicateStats returns the number of triples grouped by predicate.
func (*BoltStore) QueryByObject ¶
QueryByObject returns all triples whose object matches.
func (*BoltStore) QueryBySubject ¶
QueryBySubject returns all triples whose subject matches.
func (*BoltStore) QueryBySubjectPredicate ¶
func (s *BoltStore) QueryBySubjectPredicate(_ context.Context, subject, predicate string) ([]Triple, error)
QueryBySubjectPredicate returns triples matching both subject and predicate.
func (*BoltStore) RemoveTriple ¶
RemoveTriple removes a triple from all three indexes.
func (*BoltStore) SetPredicateValidator ¶ added in v0.7.0
func (s *BoltStore) SetPredicateValidator(v PredicateValidatorFunc)
SetPredicateValidator sets an optional predicate validator. When set, putTriple rejects triples with unrecognized predicates.
func (*BoltStore) Traverse ¶
func (s *BoltStore) Traverse(_ context.Context, startNode string, maxDepth int, predicates []string) ([]Triple, error)
Traverse performs a breadth-first traversal from startNode up to maxDepth hops. If predicates is non-empty, only edges with matching predicate types are followed.
type Extractor ¶
type Extractor struct {
// contains filtered or unexported fields
}
Extractor uses an LLM to extract entities and relationships from text.
func NewExtractor ¶
func NewExtractor(generator llm.TextGenerator, logger *zap.SugaredLogger, opts ...ExtractorOption) *Extractor
NewExtractor creates a new LLM-based entity/relationship extractor.
type ExtractorOption ¶ added in v0.7.0
type ExtractorOption func(*Extractor)
ExtractorOption configures optional Extractor behavior.
func WithPredicateValidator ¶ added in v0.7.0
func WithPredicateValidator(v PredicateValidatorFunc) ExtractorOption
WithPredicateValidator injects an ontology-backed predicate validator. When set, extracted predicates are validated against the registry. When not set, the hardcoded 9-predicate list is used as fallback.
type GraphBuffer ¶
type GraphBuffer struct {
// contains filtered or unexported fields
}
GraphBuffer collects graph update requests and processes them in batches on a background goroutine. It follows the same lifecycle pattern as embedding.EmbeddingBuffer: Start -> Enqueue -> Stop.
Note: GraphRequest items are expanded into individual Triples for batch processing, so the BatchBuffer operates on Triple slices internally.
func NewGraphBuffer ¶
func NewGraphBuffer(store Store, logger *zap.SugaredLogger) *GraphBuffer
NewGraphBuffer creates a new asynchronous graph update buffer.
func (*GraphBuffer) DroppedCount ¶
func (b *GraphBuffer) DroppedCount() int64
DroppedCount returns the total number of dropped graph requests.
func (*GraphBuffer) Enqueue ¶
func (b *GraphBuffer) Enqueue(req GraphRequest)
Enqueue submits a graph update request. Non-blocking; drops if the queue is full.
func (*GraphBuffer) Start ¶
func (b *GraphBuffer) Start(wg *sync.WaitGroup)
Start launches the background goroutine. The WaitGroup is incremented so callers can wait for graceful shutdown.
func (*GraphBuffer) Stop ¶
func (b *GraphBuffer) Stop()
Stop signals the background goroutine to drain and exit.
type GraphNode ¶
type GraphNode struct {
ID string
NodeType string // ObjectType name from triple metadata (empty = untyped)
Predicate string // the edge that led here
FromNode string // the source node this was discovered from
Depth int
}
GraphNode represents a node discovered through graph expansion.
type GraphRAGResult ¶
type GraphRAGResult struct {
// VectorResults are the original vector-search results.
VectorResults []VectorResult
// GraphResults are additional results discovered via graph traversal.
GraphResults []GraphNode
}
GraphRAGResult extends VectorResult with graph-expanded context.
type GraphRAGService ¶
type GraphRAGService struct {
// contains filtered or unexported fields
}
GraphRAGService provides hybrid retrieval combining vector search with graph expansion.
func NewGraphRAGService ¶
func NewGraphRAGService( vectorRAG VectorRetriever, graph Store, maxDepth int, maxExpand int, logger *zap.SugaredLogger, ) *GraphRAGService
NewGraphRAGService creates a new hybrid graph RAG service.
func (*GraphRAGService) AssembleSection ¶
func (s *GraphRAGService) AssembleSection(result *GraphRAGResult) string
AssembleSection builds a formatted string section for context injection.
func (*GraphRAGService) Retrieve ¶
func (s *GraphRAGService) Retrieve(ctx context.Context, query string, opts VectorRetrieveOptions) (*GraphRAGResult, error)
Retrieve performs 2-phase hybrid retrieval: Phase 1: Vector search (sqlite-vec cosine similarity) Phase 2: Graph expansion from Phase 1 results (depth 1-2 hops)
type GraphRequest ¶
type GraphRequest struct {
Triples []Triple
}
GraphRequest represents a request to add triples to the graph.
type Predicate ¶
type Predicate string
Predicate represents a relationship type in the knowledge graph.
type PredicateValidatorFunc ¶ added in v0.7.0
PredicateValidatorFunc validates whether a predicate name is recognized. Used by BoltStore for optional registry-backed validation.
type Store ¶
type Store interface {
// AddTriple adds a single triple to the graph.
AddTriple(ctx context.Context, t Triple) error
// AddTriples adds multiple triples atomically.
AddTriples(ctx context.Context, triples []Triple) error
// RemoveTriple removes a triple from the graph.
RemoveTriple(ctx context.Context, t Triple) error
// QueryBySubject returns all triples with the given subject.
QueryBySubject(ctx context.Context, subject string) ([]Triple, error)
// QueryByObject returns all triples with the given object.
QueryByObject(ctx context.Context, object string) ([]Triple, error)
// QueryBySubjectPredicate returns triples matching subject and predicate.
QueryBySubjectPredicate(ctx context.Context, subject, predicate string) ([]Triple, error)
// Traverse performs a breadth-first traversal from a start node.
// predicates filters which edge types to follow (empty = all).
Traverse(ctx context.Context, startNode string, maxDepth int, predicates []string) ([]Triple, error)
// Count returns the total number of triples in the store.
Count(ctx context.Context) (int, error)
// PredicateStats returns the number of triples for each predicate type.
PredicateStats(ctx context.Context) (map[string]int, error)
// AllTriples returns every triple in the store.
AllTriples(ctx context.Context) ([]Triple, error)
// ClearAll removes all triples from the store.
ClearAll(ctx context.Context) error
// Close closes the underlying store.
Close() error
}
Store provides graph CRUD and traversal operations.
type Triple ¶
type Triple struct {
Subject string
Predicate string
Object string
SubjectType string // ObjectType name for subject (empty = untyped)
ObjectType string // ObjectType name for object (empty = untyped)
Metadata map[string]string
}
Triple represents a Subject-Predicate-Object relationship in the graph.
type VectorResult ¶
VectorResult mirrors embedding.RAGResult to avoid an import cycle.
type VectorRetrieveOptions ¶
type VectorRetrieveOptions struct {
Collections []string
Limit int
SessionKey string
MaxDistance float32
}
VectorRetrieveOptions mirrors embedding.RetrieveOptions to avoid an import cycle.
type VectorRetriever ¶
type VectorRetriever interface {
Retrieve(ctx context.Context, query string, opts VectorRetrieveOptions) ([]VectorResult, error)
}
VectorRetriever retrieves results from a vector store. Implemented by embedding.RAGService (satisfies via adapter).