Skip to main content

brainwires_knowledge/
lib.rs

1#![deny(missing_docs)]
2//! # Brainwires Cognition — Unified Intelligence Layer
3//!
4//! This crate consolidates three previously separate crates into a single
5//! coherent intelligence layer for the Brainwires Agent Framework:
6//!
7//! ## Knowledge (from brainwires-brain)
8//! - **BrainClient** — Persistent thought storage with semantic search
9//! - **Entity/Relationship Graph** — Entity types, co-occurrence, impact analysis
10//! - **BKS** — Behavioral Knowledge System (shared truths with confidence scoring)
11//! - **PKS** — Personal Knowledge System (user-scoped facts)
12//! - **Fact Extraction** — Automatic categorization and tag extraction
13//!
14//! ## Prompting (from brainwires-prompting)
15//! - **Techniques** — 15 prompting techniques from the adaptive selection paper
16//! - **Clustering** — K-means task clustering by semantic similarity
17//! - **Generator** — Dynamic prompt generation with BKS/PKS/SEAL integration
18//! - **Learning** — Technique effectiveness tracking and BKS promotion
19//! - **Temperature** — Adaptive temperature optimization per cluster
20//!
21//! ## RAG (from brainwires-rag)
22//! - **RagClient** — Core semantic code search with hybrid BM25+vector search
23//! - **Embedding** — FastEmbed (all-MiniLM-L6-v2) local embedding generation
24//! - **Indexer** — File walking, AST-based chunking for 12 languages
25//! - **Git Search** — Semantic search over commit history
26//! - **Documents** — PDF, markdown, and plaintext document processing
27//!
28//! ## Spectral
29//! - **SpectralReranker** — MSS-inspired log-det maximization for diverse retrieval
30//! - **GraphOps** — Laplacian, Fiedler vector, spectral clustering, sparsification
31//! - **Kernel** — Relevance-weighted kernel matrix construction
32//! - **Linalg** — Cholesky decomposition and log-determinant computation
33//!
34//! ## Code Analysis
35//! - **RepoMap** — AST-based symbol extraction (definitions, references)
36//! - **Relations** — Call graph generation, definition/reference lookup
37//! - **Storage** — LanceDB persistence for code relations
38
39// Re-export core types
40pub use brainwires_core;
41
42// ── Dream (from brainwires-autonomy) ───────────────────────────────────────
43
44/// Offline memory consolidation — summarization, fact extraction, hot/warm/cold tier transitions.
45#[cfg(feature = "dream")]
46pub mod dream;
47
48// ── Knowledge (from brainwires-brain) ──────────────────────────────────────
49
50/// Knowledge graph, entities, thoughts, BKS/PKS, brain client.
51#[cfg(feature = "knowledge")]
52pub mod knowledge;
53
54// ── Prompting (from brainwires-prompting) ──────────────────────────────────
55
56/// Adaptive prompting techniques, clustering, temperature optimization.
57pub mod prompting;
58
59// ── RAG (from brainwires-rag) ──────────────────────────────────────────────
60
61/// RAG error types.
62#[cfg(feature = "rag")]
63pub mod rag;
64
65// ── Spectral math ──────────────────────────────────────────────────────────
66
67/// Spectral graph methods: diverse retrieval, clustering, centrality, sparsification.
68#[cfg(feature = "spectral")]
69pub mod spectral;
70
71// ── Code analysis ──────────────────────────────────────────────────────────
72
73/// Code relationship extraction (definitions, references, call graphs).
74#[cfg(feature = "code-analysis")]
75pub mod code_analysis;
76
77// ── Re-exports (knowledge) ─────────────────────────────────────────────────
78
79#[cfg(feature = "knowledge")]
80pub use knowledge::brain_client::BrainClient;
81#[cfg(feature = "knowledge")]
82pub use knowledge::config::{DispositionTrait, MemoryBankConfig};
83#[cfg(feature = "knowledge")]
84pub use knowledge::entity::{
85    ContradictionEvent, ContradictionKind, Entity, EntityStore, EntityStoreStats, EntityType,
86    ExtractionResult, Relationship,
87};
88#[cfg(feature = "knowledge")]
89pub use knowledge::relationship_graph::{
90    EdgeType, EntityContext, GraphEdge, GraphNode, RelationshipGraph,
91};
92#[cfg(feature = "knowledge")]
93pub use knowledge::thought::{Thought, ThoughtCategory, ThoughtSource};
94#[cfg(feature = "knowledge")]
95pub use knowledge::types::{
96    CaptureThoughtRequest, CaptureThoughtResponse, DeleteThoughtRequest, DeleteThoughtResponse,
97    GetThoughtRequest, GetThoughtResponse, ListRecentRequest, ListRecentResponse,
98    MemoryStatsRequest, MemoryStatsResponse, SearchKnowledgeRequest, SearchKnowledgeResponse,
99    SearchMemoryRequest, SearchMemoryResponse,
100};
101
102// ── Re-exports (prompting) ─────────────────────────────────────────────────
103
104#[cfg(feature = "prompting")]
105pub use prompting::clustering::{TaskCluster, TaskClusterManager, cosine_similarity};
106#[cfg(all(feature = "knowledge", feature = "prompting"))]
107pub use prompting::generator::{GeneratedPrompt, PromptGenerator};
108#[cfg(feature = "knowledge")]
109pub use prompting::learning::{ClusterSummary, PromptingLearningCoordinator, TechniqueStats};
110#[cfg(feature = "knowledge")]
111pub use prompting::library::TechniqueLibrary;
112pub use prompting::seal::SealProcessingResult;
113#[cfg(feature = "prompting-storage")]
114pub use prompting::storage::{ClusterStorage, StorageStats};
115pub use prompting::techniques::{
116    ComplexityLevel, PromptingTechnique, TaskCharacteristic, TechniqueCategory, TechniqueMetadata,
117};
118#[cfg(all(feature = "knowledge", feature = "prompting"))]
119pub use prompting::temperature::{TemperatureOptimizer, TemperaturePerformance};
120
121// ── Re-exports (RAG) ──────────────────────────────────────────────────────
122
123#[cfg(feature = "rag")]
124pub use rag::client::RagClient;
125#[cfg(feature = "rag")]
126pub use rag::config::Config;
127#[cfg(feature = "rag")]
128pub use rag::error::RagError;
129#[cfg(feature = "rag")]
130pub use rag::types::{
131    AdvancedSearchRequest, ClearRequest, ClearResponse, EnsembleRequest, EnsembleResponse,
132    FindDefinitionRequest, FindReferencesRequest, GetCallGraphRequest, GitSearchResult,
133    IndexRequest, IndexResponse, IndexingMode, LanguageStats, QueryRequest, QueryResponse,
134    SearchGitHistoryRequest, SearchGitHistoryResponse, SearchStrategy, StatisticsRequest,
135    StatisticsResponse,
136};
137#[cfg(all(feature = "rag", feature = "code-analysis"))]
138pub use rag::types::{FindDefinitionResponse, FindReferencesResponse, GetCallGraphResponse};
139
140// ── Re-exports (spectral) ─────────────────────────────────────────────────
141
142#[cfg(feature = "spectral")]
143pub use spectral::{
144    CrossEncoderConfig, CrossEncoderReranker, DiversityReranker, RerankerKind, SpectralReranker,
145    SpectralSelectConfig,
146};
147
148// ── Re-exports (code analysis) ────────────────────────────────────────────
149
150#[cfg(feature = "code-analysis")]
151pub use code_analysis::types::{
152    CallEdge, CallGraphNode, Definition, Reference, ReferenceKind, SymbolId, SymbolKind, Visibility,
153};
154
155/// Prelude for convenient imports.
156pub mod prelude {
157    #[cfg(feature = "knowledge")]
158    pub use super::knowledge::brain_client::BrainClient;
159    #[cfg(feature = "knowledge")]
160    pub use super::knowledge::entity::{Entity, EntityStore, EntityType};
161    #[cfg(feature = "knowledge")]
162    pub use super::knowledge::thought::{Thought, ThoughtCategory};
163
164    #[cfg(all(feature = "knowledge", feature = "prompting"))]
165    pub use super::prompting::generator::PromptGenerator;
166    pub use super::prompting::techniques::{PromptingTechnique, TechniqueCategory};
167
168    #[cfg(feature = "rag")]
169    pub use super::rag::client::RagClient;
170    #[cfg(feature = "rag")]
171    pub use super::rag::types::{IndexRequest, QueryRequest};
172
173    #[cfg(feature = "spectral")]
174    pub use super::spectral::SpectralReranker;
175}