semantic

package
v0.0.0-...-0f11aa8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("fact not found")

Functions

This section is empty.

Types

type Fact

type Fact interface {
	GetID() string
	GetType() FactType
	GetSources() []Source
	GetTags() []string
	GetMetadata() FactMetadata
	// contains filtered or unexported methods
}

type FactMetadata

type FactMetadata struct {
	CreatedAt    time.Time
	ValidatedAt  time.Time
	LastAccessed time.Time
	AccessCount  int
	AccessScore  float64
	Constraints  map[string]string
}

type FactType

type FactType string
const (
	FactTypeTriple    FactType = "triple"
	FactTypeStatement FactType = "statement"
)

type GraphEdge

type GraphEdge struct {
	Subject   string
	Predicate string
	Object    string
}

type GraphNode

type GraphNode struct {
	Entity string
	Facts  []Fact
}

type GraphQuery

type GraphQuery struct {
	StartEntity string
	Predicates  []string
	MaxDepth    int
	MaxResults  int
}

type GraphResult

type GraphResult struct {
	Nodes []GraphNode
	Edges []GraphEdge
}

type Memory

type Memory interface {
	Write(ctx context.Context, entity, attribute, value string) error
	Read(ctx context.Context, entity, attribute string) (string, error)
	Search(ctx context.Context, attribute, value string) ([]string, error)
	Delete(ctx context.Context, entity, attribute string) error
}

Memory defines the high-level semantic memory interface.

type Relationship

type Relationship struct {
	ID        string
	Subject   string
	Predicate string
	Object    string
	Metadata  RelationshipMetadata
}

type RelationshipMetadata

type RelationshipMetadata struct {
	CreatedAt time.Time
}

type SearchQuery

type SearchQuery struct {
	Type        *FactType
	Entity      *string
	Attribute   *string
	Value       *string
	Tag         *string
	Source      *string
	Statement   *string
	Constraints map[string]string
	Limit       int
	Offset      int
	SortBy      SortField
	SortOrder   SortOrder
}

type Service

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

func NewService

func NewService(store Store, opts ...ServiceOption) *Service

func (*Service) CalculateConfidence

func (s *Service) CalculateConfidence(metadata FactMetadata, sourceCount int) float64

func (*Service) CreateRelationship

func (s *Service) CreateRelationship(ctx context.Context, subject, predicate, object string) error

func (*Service) DeleteFact

func (s *Service) DeleteFact(ctx context.Context, id string) error

func (*Service) FindRelatedFacts

func (s *Service) FindRelatedFacts(ctx context.Context, entity string, depth int) (GraphResult, error)

func (*Service) FindRelatedFactsWithPredicates

func (s *Service) FindRelatedFactsWithPredicates(ctx context.Context, entity string, depth int, predicates []string) (GraphResult, error)

func (*Service) ReadFact

func (s *Service) ReadFact(ctx context.Context, id string) (Fact, error)

func (*Service) Search

func (s *Service) Search(ctx context.Context, query SearchQuery) ([]Fact, error)

func (*Service) TrackAccess

func (s *Service) TrackAccess(ctx context.Context, factID string) error

func (*Service) ValidateFact

func (s *Service) ValidateFact(ctx context.Context, factID string) error

func (*Service) WriteStatement

func (s *Service) WriteStatement(ctx context.Context, fact StatementFact) error

func (*Service) WriteTriple

func (s *Service) WriteTriple(ctx context.Context, fact TripleFact) error

type ServiceOption

type ServiceOption func(*Service)

func WithMeter

func WithMeter(meter metric.Meter) ServiceOption

func WithTracer

func WithTracer(tracer trace.Tracer) ServiceOption

type SortField

type SortField string
const (
	SortByCreatedAt   SortField = "created_at"
	SortByValidatedAt SortField = "validated_at"
	SortByAccessScore SortField = "access_score"
	SortByRelevance   SortField = "relevance"
)

type SortOrder

type SortOrder string
const (
	SortAsc  SortOrder = "asc"
	SortDesc SortOrder = "desc"
)

type Source

type Source struct {
	URI         string
	RetrievedAt time.Time
}

type StatementFact

type StatementFact struct {
	ID        string
	Statement string
	Sources   []Source
	Tags      []string
	Metadata  FactMetadata
}

func (StatementFact) GetID

func (f StatementFact) GetID() string

func (StatementFact) GetMetadata

func (f StatementFact) GetMetadata() FactMetadata

func (StatementFact) GetSources

func (f StatementFact) GetSources() []Source

func (StatementFact) GetTags

func (f StatementFact) GetTags() []string

func (StatementFact) GetType

func (f StatementFact) GetType() FactType

type Store

type Store interface {
	WriteTriple(ctx context.Context, fact TripleFact) error
	WriteStatement(ctx context.Context, fact StatementFact) error
	WriteTriples(ctx context.Context, facts []TripleFact) error
	WriteStatements(ctx context.Context, facts []StatementFact) error

	ReadFact(ctx context.Context, id string) (Fact, error)
	ReadTriple(ctx context.Context, id string) (TripleFact, error)
	ReadStatement(ctx context.Context, id string) (StatementFact, error)

	Search(ctx context.Context, query SearchQuery) ([]Fact, error)

	DeleteFact(ctx context.Context, id string) error
	DeleteByEntityAttribute(ctx context.Context, entity, attribute string) error

	WriteRelationship(ctx context.Context, rel Relationship) error
	ReadRelationships(ctx context.Context, subject string) ([]Relationship, error)
	DeleteRelationship(ctx context.Context, id string) error
	TraverseGraph(ctx context.Context, query GraphQuery) (GraphResult, error)

	Close() error
}

type TripleFact

type TripleFact struct {
	ID        string
	Entity    string
	Attribute string
	Value     string
	Sources   []Source
	Tags      []string
	Metadata  FactMetadata
}

func (TripleFact) GetID

func (f TripleFact) GetID() string

func (TripleFact) GetMetadata

func (f TripleFact) GetMetadata() FactMetadata

func (TripleFact) GetSources

func (f TripleFact) GetSources() []Source

func (TripleFact) GetTags

func (f TripleFact) GetTags() []string

func (TripleFact) GetType

func (f TripleFact) GetType() FactType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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