Documentation
¶
Overview ¶
File: internal/knowledgegraph/postgres_kg.go
Index ¶
- type DBPool
- type InMemoryKG
- func (kg *InMemoryKG) AddEdge(ctx context.Context, edge schemas.Edge) error
- func (kg *InMemoryKG) AddNode(ctx context.Context, node schemas.Node) error
- func (kg *InMemoryKG) GetEdge(ctx context.Context, id string) (schemas.Edge, error)
- func (kg *InMemoryKG) GetEdges(ctx context.Context, nodeID string) ([]schemas.Edge, error)
- func (kg *InMemoryKG) GetNeighbors(ctx context.Context, nodeID string) ([]schemas.Node, error)
- func (kg *InMemoryKG) GetNode(ctx context.Context, id string) (schemas.Node, error)
- func (kg *InMemoryKG) QueryImprovementHistory(ctx context.Context, goalObjective string, limit int) ([]schemas.Node, error)
- type PostgresKG
- func (p *PostgresKG) AddEdge(ctx context.Context, edge schemas.Edge) error
- func (p *PostgresKG) AddNode(ctx context.Context, node schemas.Node) error
- func (p *PostgresKG) GetEdge(ctx context.Context, id string) (schemas.Edge, error)
- func (p *PostgresKG) GetEdges(ctx context.Context, nodeID string) ([]schemas.Edge, error)
- func (p *PostgresKG) GetNeighbors(ctx context.Context, nodeID string) ([]schemas.Node, error)
- func (p *PostgresKG) GetNode(ctx context.Context, id string) (schemas.Node, error)
- func (p *PostgresKG) QueryImprovementHistory(ctx context.Context, goalObjective string, limit int) ([]schemas.Node, error)
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 ¶
AddEdge adds an edge to the graph. If an edge with the same ID already exists, it's overwritten.
func (*InMemoryKG) AddNode ¶
AddNode adds a node to the graph. If a node with the same ID already exists, it is overwritten.
func (*InMemoryKG) GetNeighbors ¶
GetNeighbors finds all nodes connected from the given node.
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) AddNode ¶
AddNode inserts a new node or updates an existing one using an "upsert" operation.
func (*PostgresKG) GetNeighbors ¶
GetNeighbors retrieves all nodes directly connected from a given node.
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.