Skip to main content

klieo_memory_graph_rag/
lib.rs

1#![deny(missing_docs)]
2#![deny(rust_2018_idioms)]
3#![deny(rustdoc::broken_intra_doc_links)]
4
5//! `klieo-memory-graph-rag` — graph-first RAG composer.
6//!
7//! Stable at `1.x`. Trait freeze contract recorded in ADR-039
8//! (`docs/adr/adr-039-graphrag-1-0-promotion.md`).
9//!
10//! Public surface:
11//! - `BuiltinExtractor`, `FallbackExtractor`, `LlmEntityExtractor`
12//! - `ProvenanceKnowledgeGraph` — wraps any `KnowledgeGraph` with a
13//!   `ProvenanceRepository` so every `index()` mints a v2 chain
14//!   entry and every `recall_paths()` attaches the entry per hop
15//!   (ADR-038).
16//! - `VerbalizationPipeline` — LLM-driven prose summary of a
17//!   `RetrievalPath` under a `klieo-spec` `QualityLoop`.
18//! - `RegulationIngestTool` — `ImportSource` for structured
19//!   regulatory texts (DORA, AI-Act) — pre-seeds typed
20//!   `Article` / `Obligation` / `Deadline` entity hints.
21//! - `GraphAwareLongTerm` — drop-in `LongTermMemory` that issues
22//!   graph-first recall with vector fallback; `recall_traced` exposes
23//!   the same authoritative facts plus a `RecallTrace` of extracted
24//!   entities and graph paths for "why did retrieval return this?"
25//! - `KnowledgeIngestionPipeline` + `ImportSource` extension point
26//! - `InMemoryFilterableLongTerm` — zero-infra `FilterableLongTermMemory`
27//!   with real cosine similarity over an injected `Embedder`
28//!
29//! # Quickstart
30//!
31//! ```no_run
32//! # use std::sync::Arc;
33//! # use klieo_memory_graph::{FilterableLongTermMemory, KnowledgeGraph};
34//! # use klieo_memory_graph_rag::GraphAwareLongTerm;
35//! # fn run(vector: Arc<dyn FilterableLongTermMemory>, graph: Arc<dyn KnowledgeGraph>) {
36//! let long_term = GraphAwareLongTerm::builder().build(vector, graph);
37//! # let _ = long_term; }
38//! ```
39//!
40//! [`GraphAwareLongTerm::builder`] defaults the extractor
41//! ([`BuiltinExtractor`]) and the [`klieo_memory_graph::RecallMetrics`]
42//! counter so callers only supply the two mandatory backends. Override
43//! either via [`GraphAwareLongTermBuilder::extractor`] /
44//! [`GraphAwareLongTermBuilder::metrics`] /
45//! [`GraphAwareLongTermBuilder::min_graph_hits`].
46
47/// Regex-driven entity recogniser and (future) extractor combinators.
48pub mod extractor;
49/// Two-stage extractor combinator: secondary runs only when primary is empty.
50pub mod fallback_extractor;
51/// `GraphAwareLongTerm` — graph-first RAG composer over vector + graph.
52pub mod graph_aware;
53/// `KnowledgeIngestionPipeline` + `ImportSource` — bulk-ingest extension point.
54pub mod import;
55/// In-memory [`FilterableLongTermMemory`] with real cosine similarity.
56pub mod in_memory_vector;
57/// LLM-backed entity extractor — JSON-array prompt with hint-fallback.
58pub mod llm_extractor;
59/// Shared reserved metadata-key constants for the ingest/recall contract.
60pub mod metadata;
61/// `VerbalizationPipeline` — LLM-driven verbalisation of a
62/// `RetrievalPath` under a `klieo-spec` `QualityLoop`.
63pub mod path_rag;
64/// `ProvenanceKnowledgeGraph` — wraps a `KnowledgeGraph` with a
65/// `klieo-provenance` chain bridge (see ADR-038).
66pub mod provenance;
67/// Regulatory-text ingest source — DORA / AI-Act and friends.
68pub mod regulation;
69
70pub use extractor::BuiltinExtractor;
71pub use fallback_extractor::FallbackExtractor;
72pub use graph_aware::{GraphAwareLongTerm, GraphAwareLongTermBuilder, RecallTrace};
73pub use import::{ImportDocument, ImportError, ImportSource, KnowledgeIngestionPipeline};
74pub use in_memory_vector::InMemoryFilterableLongTerm;
75pub use llm_extractor::LlmEntityExtractor;
76pub use metadata::{
77    KEY_ENTITIES, KEY_IMPORT_SOURCE_ID, KEY_TITLE, KEY_VALID_FROM, RESERVED_METADATA_KEYS,
78};
79pub use path_rag::{
80    LlmRefiner, VerbalizationCritic, VerbalizationPipeline, DEFAULT_MAX_ITERATIONS,
81};
82pub use provenance::{ProvenanceKnowledgeGraph, DEFAULT_FACT_INDEX_CAPACITY, FORGET_EVENT_LABEL};
83pub use regulation::{RegulationDocument, RegulationIngestTool};