knowledgegraph

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

File: internal/knowledgegraph/postgres_kg.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBPool

type DBPool interface {
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Close()
}

DBPool defines an interface for pgxpool.Pool methods, enabling easy mocking for tests.

type InMemoryKG

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

InMemoryKG provides a fast, ephemeral, in-memory implementation of the KnowledgeGraph interface. It's great for testing, short lived scripts, or situations where persistence isn't required.

func NewInMemoryKG

func NewInMemoryKG(logger *zap.Logger) (*InMemoryKG, error)

NewInMemoryKG creates a new, empty in-memory knowledge graph.

func (*InMemoryKG) AddEdge

func (kg *InMemoryKG) AddEdge(ctx context.Context, edge schemas.Edge) error

AddEdge adds an edge to the graph. If an edge with the same ID already exists, it's overwritten.

func (*InMemoryKG) AddNode

func (kg *InMemoryKG) AddNode(ctx context.Context, node schemas.Node) error

AddNode adds a node to the graph. If a node with the same ID already exists, it is overwritten.

func (*InMemoryKG) GetEdge

func (kg *InMemoryKG) GetEdge(ctx context.Context, id string) (schemas.Edge, error)

GetEdge retrieves an edge by its ID.

func (*InMemoryKG) GetEdges

func (kg *InMemoryKG) GetEdges(ctx context.Context, nodeID string) ([]schemas.Edge, error)

GetEdges retrieves all outgoing edges from a specific node ID.

func (*InMemoryKG) GetNeighbors

func (kg *InMemoryKG) GetNeighbors(ctx context.Context, nodeID string) ([]schemas.Node, error)

GetNeighbors finds all nodes connected from the given node.

func (*InMemoryKG) GetNode

func (kg *InMemoryKG) GetNode(ctx context.Context, id string) (schemas.Node, error)

GetNode retrieves a node by its ID.

func (*InMemoryKG) QueryImprovementHistory

func (kg *InMemoryKG) QueryImprovementHistory(ctx context.Context, goalObjective string, limit int) ([]schemas.Node, error)

QueryImprovementHistory finds past improvement attempts related to the current goal objective. This provides the "memory" for the Reflective OODA loop.

type PostgresKG

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

PostgresKG provides a persistent implementation of the KnowledgeGraphClient using PostgreSQL.

func NewPostgresKG

func NewPostgresKG(pool DBPool, logger *zap.Logger) *PostgresKG

NewPostgresKG initializes a new connection wrapper for the PostgreSQL database.

func (*PostgresKG) AddEdge

func (p *PostgresKG) AddEdge(ctx context.Context, edge schemas.Edge) error

AddEdge inserts a new edge or updates an existing one based on its ID.

func (*PostgresKG) AddNode

func (p *PostgresKG) AddNode(ctx context.Context, node schemas.Node) error

AddNode inserts a new node or updates an existing one using an "upsert" operation.

func (*PostgresKG) GetEdge

func (p *PostgresKG) GetEdge(ctx context.Context, id string) (schemas.Edge, error)

GetEdge fetches a single edge from the database by its ID.

func (*PostgresKG) GetEdges

func (p *PostgresKG) GetEdges(ctx context.Context, nodeID string) ([]schemas.Edge, error)

GetEdges finds all outgoing edges originating from a specific node.

func (*PostgresKG) GetNeighbors

func (p *PostgresKG) GetNeighbors(ctx context.Context, nodeID string) ([]schemas.Node, error)

GetNeighbors retrieves all nodes directly connected from a given node.

func (*PostgresKG) GetNode

func (p *PostgresKG) GetNode(ctx context.Context, id string) (schemas.Node, error)

GetNode fetches a single node from the database by its ID.

func (*PostgresKG) QueryImprovementHistory

func (p *PostgresKG) QueryImprovementHistory(ctx context.Context, goalObjective string, limit int) ([]schemas.Node, error)

QueryImprovementHistory retrieves past improvement attempts using efficient JSONB queries.

Jump to

Keyboard shortcuts

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