kb

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package kb talks to kb-query, the Python service that runs Graphiti search against one FalkorDB instance. The MCP server never touches FalkorDB directly; it only calls kb-query for the graphs a request may read.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityDay

type ActivityDay struct {
	Day       string `json:"day"`
	Documents int    `json:"documents"`
}

ActivityDay is how many documents a brain ingested on one UTC day.

type ActivityRequest

type ActivityRequest struct {
	Graph string    `json:"graph"`
	Since time.Time `json:"since"`
}

ActivityRequest is sent to kb-query's /activity endpoint.

type Client

type Client struct {
	HTTP *http.Client
}

Client is the HTTP implementation of Reader.

func NewClient

func NewClient() *Client

NewClient returns a client with a sane timeout.

func (*Client) Activity

func (c *Client) Activity(ctx context.Context, backend string, req ActivityRequest) ([]ActivityDay, error)

Activity calls POST {backend}/activity.

func (*Client) Graph

func (c *Client) Graph(ctx context.Context, backend string, req GraphRequest) (Graph, error)

Graph calls POST {backend}/graph.

func (*Client) Recent

func (c *Client) Recent(ctx context.Context, backend string, req RecentRequest) ([]Document, error)

Recent calls POST {backend}/recent.

func (*Client) Search

func (c *Client) Search(ctx context.Context, backend string, req SearchRequest) ([]Fact, error)

Search calls POST {backend}/search.

func (*Client) Stats

func (c *Client) Stats(ctx context.Context, backend, graph string) (Stats, error)

Stats calls POST {backend}/stats.

type Document

type Document struct {
	Brain       string     `json:"brain"`
	Kind        Kind       `json:"kind"`
	Source      string     `json:"source"`
	CommittedAt *time.Time `json:"committed_at,omitempty"`
}

Document is one ingested file, as listed by /recent.

type Fact

type Fact struct {
	Brain     string     `json:"brain"`
	Kind      Kind       `json:"kind"`
	Fact      string     `json:"fact"`
	Source    string     `json:"source,omitempty"`
	ValidAt   *time.Time `json:"valid_at,omitempty"`
	InvalidAt *time.Time `json:"invalid_at,omitempty"`
	Score     float64    `json:"score"`
}

Fact is one retrieved Graphiti edge, flattened for packing.

func Resolve

func Resolve(facts []Fact) []Fact

Resolve returns each fact once: a repeat of the same kind and text, however spaced or cased, is dropped. Facts keep their original order; the input is not modified.

func (Fact) Current

func (f Fact) Current() bool

Current reports whether the fact has not been superseded.

type Graph

type Graph struct {
	Nodes []GraphNode `json:"nodes"`
	Edges []GraphEdge `json:"edges"`
}

Graph is a small subgraph of one brain: every edge has both endpoints in Nodes.

type GraphEdge

type GraphEdge struct {
	ID        string     `json:"id"`
	From      string     `json:"from"`
	To        string     `json:"to"`
	Name      string     `json:"name"`
	Fact      string     `json:"fact"`
	Kind      Kind       `json:"kind"`
	Source    string     `json:"source,omitempty"`
	ValidAt   *time.Time `json:"valid_at,omitempty"`
	InvalidAt *time.Time `json:"invalid_at,omitempty"`
}

GraphEdge is one fact linking two entities of a brain. From and To are node ids.

type GraphNode

type GraphNode struct {
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	Summary string   `json:"summary"`
	Labels  []string `json:"labels"`
}

GraphNode is one entity of a brain, as drawn by /graph.

type GraphRequest

type GraphRequest struct {
	Graph string `json:"graph"`
	Query string `json:"query,omitempty"`
	Node  string `json:"node,omitempty"`
	Limit int    `json:"limit"`
}

GraphRequest is sent to kb-query's /graph endpoint: exactly one of Query and Node.

type Kind

type Kind string

Kind classifies a fact for context packing.

const (
	KindDecision   Kind = "decision"
	KindConvention Kind = "convention"
	KindState      Kind = "state"
	KindPointer    Kind = "pointer"
)

type Reader

type Reader interface {
	Searcher
	Stats(ctx context.Context, backend, graph string) (Stats, error)
	Recent(ctx context.Context, backend string, req RecentRequest) ([]Document, error)
	Activity(ctx context.Context, backend string, req ActivityRequest) ([]ActivityDay, error)
	Graph(ctx context.Context, backend string, req GraphRequest) (Graph, error)
}

Reader is everything the MCP server asks of kb-query; the HTTP client implements it and tests use a fake.

type RecentRequest

type RecentRequest struct {
	Graph string     `json:"graph"`
	Since *time.Time `json:"since,omitempty"`
	Limit int        `json:"limit"`
}

RecentRequest is sent to kb-query's /recent endpoint.

type SearchRequest

type SearchRequest struct {
	Graph string `json:"graph"`
	Query string `json:"query"`
	Limit int    `json:"limit"`
	// Kinds optionally restricts results, e.g. only decisions.
	Kinds []Kind `json:"kinds,omitempty"`
}

SearchRequest is sent to kb-query's /search endpoint.

type Searcher

type Searcher interface {
	Search(ctx context.Context, backend string, req SearchRequest) ([]Fact, error)
}

Searcher is the retrieval interface.

type Stats

type Stats struct {
	// Documents counts files, however many sections each was split into.
	Documents  int        `json:"documents"`
	LastIngest *time.Time `json:"last_ingest,omitempty"`
}

Stats is what one brain's graph holds.

Jump to

Keyboard shortcuts

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