Skip to main content

brainwires_cognition/
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// ── Knowledge (from brainwires-brain) ──────────────────────────────────────
43
44/// Knowledge graph, entities, thoughts, BKS/PKS, brain client.
45#[cfg(feature = "knowledge")]
46pub mod knowledge;
47
48// ── Prompting (from brainwires-prompting) ──────────────────────────────────
49
50/// Adaptive prompting techniques, clustering, temperature optimization.
51pub mod prompting;
52
53// ── RAG (from brainwires-rag) ──────────────────────────────────────────────
54
55/// RAG error types.
56#[cfg(feature = "rag")]
57pub mod rag;
58
59// ── Spectral math ──────────────────────────────────────────────────────────
60
61/// Spectral graph methods: diverse retrieval, clustering, centrality, sparsification.
62#[cfg(feature = "spectral")]
63pub mod spectral;
64
65// ── Code analysis ──────────────────────────────────────────────────────────
66
67/// Code relationship extraction (definitions, references, call graphs).
68#[cfg(feature = "code-analysis")]
69pub mod code_analysis;
70
71// ── Re-exports (knowledge) ─────────────────────────────────────────────────
72
73#[cfg(feature = "knowledge")]
74pub use knowledge::brain_client::BrainClient;
75#[cfg(feature = "knowledge")]
76pub use knowledge::entity::{
77    ContradictionEvent, ContradictionKind, Entity, EntityStore, EntityStoreStats, EntityType,
78    ExtractionResult, Relationship,
79};
80#[cfg(feature = "knowledge")]
81pub use knowledge::relationship_graph::{
82    EdgeType, EntityContext, GraphEdge, GraphNode, RelationshipGraph,
83};
84#[cfg(feature = "knowledge")]
85pub use knowledge::thought::{Thought, ThoughtCategory, ThoughtSource};
86#[cfg(feature = "knowledge")]
87pub use knowledge::types::{
88    CaptureThoughtRequest, CaptureThoughtResponse, DeleteThoughtRequest, DeleteThoughtResponse,
89    GetThoughtRequest, GetThoughtResponse, ListRecentRequest, ListRecentResponse,
90    MemoryStatsRequest, MemoryStatsResponse, SearchKnowledgeRequest, SearchKnowledgeResponse,
91    SearchMemoryRequest, SearchMemoryResponse,
92};
93
94// ── Re-exports (prompting) ─────────────────────────────────────────────────
95
96#[cfg(feature = "prompting")]
97pub use prompting::clustering::{TaskCluster, TaskClusterManager, cosine_similarity};
98#[cfg(feature = "knowledge")]
99pub use prompting::generator::{GeneratedPrompt, PromptGenerator};
100#[cfg(feature = "knowledge")]
101pub use prompting::learning::{ClusterSummary, PromptingLearningCoordinator, TechniqueStats};
102#[cfg(feature = "knowledge")]
103pub use prompting::library::TechniqueLibrary;
104pub use prompting::seal::SealProcessingResult;
105#[cfg(feature = "prompting-storage")]
106pub use prompting::storage::{ClusterStorage, StorageStats};
107pub use prompting::techniques::{
108    ComplexityLevel, PromptingTechnique, TaskCharacteristic, TechniqueCategory, TechniqueMetadata,
109};
110#[cfg(feature = "knowledge")]
111pub use prompting::temperature::{TemperatureOptimizer, TemperaturePerformance};
112
113// ── Re-exports (RAG) ──────────────────────────────────────────────────────
114
115#[cfg(feature = "rag")]
116pub use rag::client::RagClient;
117#[cfg(feature = "rag")]
118pub use rag::config::Config;
119#[cfg(feature = "rag")]
120pub use rag::error::RagError;
121#[cfg(feature = "rag")]
122pub use rag::types::{
123    AdvancedSearchRequest, ClearRequest, ClearResponse, FindDefinitionRequest,
124    FindReferencesRequest, GetCallGraphRequest, GitSearchResult, IndexRequest, IndexResponse,
125    IndexingMode, LanguageStats, QueryRequest, QueryResponse, SearchGitHistoryRequest,
126    SearchGitHistoryResponse, StatisticsRequest, StatisticsResponse,
127};
128#[cfg(all(feature = "rag", feature = "code-analysis"))]
129pub use rag::types::{FindDefinitionResponse, FindReferencesResponse, GetCallGraphResponse};
130
131// ── Re-exports (spectral) ─────────────────────────────────────────────────
132
133#[cfg(feature = "spectral")]
134pub use spectral::SpectralReranker;
135
136// ── Re-exports (code analysis) ────────────────────────────────────────────
137
138#[cfg(feature = "code-analysis")]
139pub use code_analysis::types::{
140    CallEdge, CallGraphNode, Definition, Reference, ReferenceKind, SymbolId, SymbolKind, Visibility,
141};
142
143/// Prelude for convenient imports.
144pub mod prelude {
145    #[cfg(feature = "knowledge")]
146    pub use super::knowledge::brain_client::BrainClient;
147    #[cfg(feature = "knowledge")]
148    pub use super::knowledge::entity::{Entity, EntityStore, EntityType};
149    #[cfg(feature = "knowledge")]
150    pub use super::knowledge::thought::{Thought, ThoughtCategory};
151
152    #[cfg(feature = "knowledge")]
153    pub use super::prompting::generator::PromptGenerator;
154    pub use super::prompting::techniques::{PromptingTechnique, TechniqueCategory};
155
156    #[cfg(feature = "rag")]
157    pub use super::rag::client::RagClient;
158    #[cfg(feature = "rag")]
159    pub use super::rag::types::{IndexRequest, QueryRequest};
160
161    #[cfg(feature = "spectral")]
162    pub use super::spectral::SpectralReranker;
163}