/** * Memory Knowledge Graph — entities, relations, and rules distilled from * agent sessions and org runs (cognee-concept port, Phase 2 of * docs/mastermind/2026-07-19-cognee-port-plan.md). * * Storage rides store A (memory-bridge) rather than a dedicated SQLite DB: * nodes live in namespace `kg:nodes`, edges in `kg:edges`, distilled rules * additionally in `rules` (so existing knowledge/injection surfaces find them). * That buys embeddings, upsert, sql.js fallback, and the Phase 1 * feedback/frequency weighting for free — KG node ranking improves with use * automatically. * * Identity is deterministic and NAME-ONLY (cognee's Entity.identity_fields): * the entry KEY is `n:`, so the same entity extracted from * any session merges idempotently via upsert regardless of assigned type. * Every write carries `origin_refs` so a bad ingest can be rolled back per * run/session. * * // monolean: graph traversal is in-process over a full kg:edges list — * // fine to ~10k edges; upgrade path is a real SQLite edges table with * // indexed src/dst columns if orgs outgrow that. * * @module v1/cli/memory/memory-kg */ export declare const KG_NODES_NS = "kg:nodes"; export declare const KG_EDGES_NS = "kg:edges"; export declare const RULES_NS = "rules"; export interface KgNodeInput { name: string; /** Basic type, cognee-style ("Person", "Tool", "Service") — not over-specific. */ type?: string; description?: string; nodeSet?: string; } export interface KgEdgeInput { source: string; target: string; /** snake_case relation name. */ relation: string; /** One-sentence concrete fact using the endpoint names. */ description?: string; sourceType?: string; targetType?: string; } export interface KgIngestResult { success: boolean; nodesAdded: number; nodesMerged: number; edgesAdded: number; edgesMerged: number; error?: string; } /** cognee DataPoint normalization: lowercase, spaces→_, strip apostrophes. */ export declare function normalizeName(name: string): string; /** Identity is NAME-ONLY (cognee's Entity.identity_fields = ["name"]) — type * lives in metadata. Including type in the key forked the same entity when * the LLM said "Module" and the heuristic said "entity". */ export declare function nodeKey(_type: string, name: string): string; /** Idempotently merge extracted nodes/edges into the KG. Same-name entities * collapse onto one node (deterministic key + upsert); origin_refs accumulate * so rollback can undo a single run's contribution. */ export declare function kgIngest(options: { nodes: KgNodeInput[]; edges?: KgEdgeInput[]; /** Provenance: run id, session id, or doc hash this extraction came from. */ originRef: string; dbPath?: string; }): Promise; export interface RuleVerdict { rule: string; verdict: 'accepted' | 'already_known' | 'invalid'; similarTo?: string; } /** Stage-2 of cognee's curator/writer distillation: the CALLER (an LLM agent) * proposes candidate rules; this accepts each unless a semantically * near-identical rule exists (embedding dedup — deterministic keys can't * collapse paraphrases). Accepted rules are stored both as KG nodes * (node_set=rules) and as plain `rules`-namespace entries so the existing * injection/search surfaces pick them up with zero new plumbing. */ export declare function kgIngestRules(options: { rules: { rule: string; context?: string; }[]; originRef: string; dbPath?: string; /** Similarity above which a candidate is already_known (default 0.78 — * MiniLM paraphrases of the same rule commonly land 0.78-0.9; cognee's * equivalent control is prompt-injected LLM judgment, which we approximate). */ dedupThreshold?: number; }): Promise<{ success: boolean; verdicts: RuleVerdict[]; accepted: number; error?: string; }>; /** List stored rules (for injection or review). */ export declare function kgListRules(options?: { dbPath?: string; limit?: number; }): Promise<{ rule: string; key: string; }[]>; export interface KgSearchResult { success: boolean; /** Rendered triplet lines, best first. */ context: string; triplets: { source: string; relation: string; target: string; fact: string; score: number; }[]; seeds: { name: string; type: string; description: string; score: number; id: string; }[]; error?: string; } /** Vector-seed → neighborhood → triplet ranking (cognee's brute-force triplet * search, scaled down). Seed scores already carry the Phase 1 feedback blend. */ export declare function kgSearch(options: { query: string; dbPath?: string; limit?: number; nodeSet?: string; }): Promise; export declare function kgGlossary(options?: { dbPath?: string; limit?: number; }): Promise; /** Delete every node/edge/rule whose ONLY origin is `originRef`. Elements with * other origins survive (shared knowledge isn't destroyed by one bad run); * their origin lists retain the ref — acceptable residue. * // monolean: no origin-list rewrite — needs an update-by-id bridge API */ export declare function kgRollback(options: { originRef: string; dbPath?: string; }): Promise<{ success: boolean; deleted: number; retained: number; error?: string; }>; export interface ConsolidationCandidate { name: string; type: string; description: string; edgeCount: number; /** Neighborhood facts to merge into one canonical description. */ neighborhood: string[]; } /** Entities whose descriptions are stale relative to their connectivity — * the LLM half runs in the LIVE agent: it rewrites each candidate's * description from the neighborhood facts and resubmits via memory_kg_ingest * (longer descriptions win on merge). No LLM here (fully local constraint). */ export declare function kgConsolidateCandidates(options?: { dbPath?: string; /** Minimum edges for a node to qualify (default 3). */ minEdges?: number; limit?: number; }): Promise; export declare function kgStats(options?: { dbPath?: string; }): Promise<{ nodes: number; edges: number; rules: number; }>; /** Regex extraction for when no LLM is in the loop (memory-palace lineage): * proper-noun phrases and `code identifiers` become entities, sentence * co-occurrence becomes relates_to edges. Lower-trust by design — real * entity/relation quality comes from the LLM path (memory_kg_ingest called * by the live agent, or the org coordinator's org_learn tool). */ export declare function heuristicExtract(text: string, opts?: { sourceName?: string; }): { nodes: KgNodeInput[]; edges: KgEdgeInput[]; }; //# sourceMappingURL=memory-kg.d.ts.map