-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.rs
More file actions
282 lines (247 loc) · 8.54 KB
/
Copy pathlib.rs
File metadata and controls
282 lines (247 loc) · 8.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//! # LadybugDB
//!
//! Unified cognitive database: SQL + Cypher + Vector + Hamming + NARS + Counterfactuals.
//! Built on Lance columnar storage with AGI operations as first-class primitives.
//!
//! ## Quick Start
//! ```rust,ignore
//! use ladybug::{Database, Thought, NodeRecord, cypher_to_sql};
//!
//! // Open database
//! let db = Database::open("./mydb").await?;
//!
//! // SQL queries (via DataFusion)
//! let results = db.sql("SELECT * FROM nodes WHERE label = 'Thought'").await?;
//!
//! // Cypher queries (auto-transpiled to recursive CTEs)
//! let paths = db.cypher("MATCH (a)-[:CAUSES*1..5]->(b) RETURN b").await?;
//!
//! // Vector search (via LanceDB ANN)
//! let similar = db.vector_search(&embedding, 10).await?;
//!
//! // Resonance search (Hamming similarity on 10K-bit fingerprints)
//! let resonant = db.resonate(&fingerprint, 0.7, 10);
//!
//! // Grammar Triangle (universal input layer)
//! use ladybug::grammar::GrammarTriangle;
//! let triangle = GrammarTriangle::from_text("I want to understand this");
//! let fingerprint = triangle.to_fingerprint();
//!
//! // Butterfly detection (causal amplification chains)
//! let butterflies = db.detect_butterflies("change_id", 5.0, 10).await?;
//!
//! // Counterfactual reasoning
//! let forked = db.fork();
//! ```
//!
//! ## Architecture
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ LADYBUGDB │
//! ├─────────────────────────────────────────────────────────────────┤
//! │ │
//! │ Grammar → NSM + Causality + Qualia → 10K Fingerprint │
//! │ SQL → DataFusion + Custom UDFs (hamming, similarity) │
//! │ Cypher → Parser + Transpiler → Recursive CTEs │
//! │ Vector → LanceDB native ANN indices │
//! │ Hamming → AVX-512 SIMD (65M comparisons/sec) │
//! │ NARS → Non-Axiomatic Reasoning System │
//! │ Storage: Lance columnar format, zero-copy Arrow │
//! │ Indices: IVF-PQ (vector), scalar (labels), Hamming (custom) │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
// portable_simd requires nightly - use fallback popcount instead
// #![cfg_attr(feature = "simd", feature(portable_simd))]
#![allow(dead_code)]
// Clippy: allow stylistic lints across the codebase
#![allow(
clippy::collapsible_if,
clippy::needless_range_loop,
clippy::manual_range_contains,
clippy::derivable_impls,
clippy::manual_div_ceil,
clippy::redundant_closure,
clippy::manual_is_multiple_of,
clippy::needless_borrow,
clippy::needless_borrows_for_generic_args,
clippy::large_enum_variant,
clippy::unnecessary_map_or,
clippy::manual_clamp,
clippy::if_same_then_else,
clippy::let_and_return,
clippy::redundant_pattern_matching,
clippy::manual_memcpy,
clippy::unnecessary_cast,
clippy::new_without_default,
clippy::len_without_is_empty,
clippy::too_many_arguments,
clippy::type_complexity,
clippy::single_match,
clippy::needless_return,
clippy::single_char_add_str,
clippy::unnecessary_unwrap,
clippy::manual_find,
clippy::manual_strip,
clippy::get_first,
clippy::len_zero,
clippy::unnecessary_sort_by,
clippy::implicit_saturating_sub,
clippy::cast_abs_to_unsigned,
clippy::manual_abs_diff,
clippy::cloned_ref_to_slice_refs,
clippy::unwrap_or_default,
clippy::doc_lazy_continuation
)]
// === Core modules ===
pub mod chess; // Chess position fingerprinting (16K-bit → RESONATE)
pub mod cognitive;
pub mod container;
pub mod core;
pub mod fabric;
pub mod grammar; // Grammar Triangle
pub mod graph;
pub mod learning;
pub mod nars;
pub mod query;
pub mod search;
pub mod storage;
pub mod width_16k;
pub mod world;
pub mod spectroscopy;
pub mod qualia;
pub mod mul; // Meta-Uncertainty Layer (10-layer metacognition)
pub mod cypher_bridge; // Cypher string → BindSpace operations (neo4j-rs bridge)
pub mod spo; // Subject-Predicate-Object — core cognitive substrate (always-on)
// === Unified execution contract (crewai-rust × ada-n8n integration) ===
pub mod contract;
// === Optional extensions (codebook, hologram, compress only) ===
#[cfg(any(
feature = "codebook",
feature = "hologram",
feature = "compress"
))]
pub mod extensions;
#[cfg(feature = "python")]
pub mod python;
#[cfg(feature = "bench")]
pub mod bench;
#[cfg(feature = "flight")]
pub mod flight;
#[cfg(feature = "crewai")]
pub mod orchestration;
// === Re-exports for convenience ===
// Core types
pub use crate::core::{DIM, DIM_U64, Embedding, Fingerprint, VsaOps};
// Chess position fingerprinting
pub use crate::chess::{ChessFingerprint, ChessPosition, GamePhase};
// Cognitive types
pub use crate::cognitive::{Belief, Concept, ThinkingStyle, Thought};
// NARS (Non-Axiomatic Reasoning)
pub use crate::nars::{Abduction, Deduction, Evidence, Induction, TruthValue};
// Grammar Triangle (universal input layer)
pub use crate::grammar::{CausalityFlow, GrammarTriangle, NSMField, QualiaField};
// Graph traversal
pub use crate::graph::{Edge, EdgeType, Traversal};
// Counterfactual worlds
pub use crate::world::{Change, Counterfactual, World};
// Query engine
pub use crate::query::{Query, QueryBuilder, QueryResult, SqlEngine, cypher_to_sql};
// Storage
#[cfg(feature = "lancedb")]
pub use crate::storage::{Database, EdgeRecord, LanceStore, NodeRecord};
// Orchestration (crewAI integration)
#[cfg(feature = "crewai")]
pub use crate::orchestration::{
A2AChannel,
A2AMessage,
A2AProtocol,
AgentAwareness,
AgentBlackboard,
AgentCapability,
AgentCard,
AgentGoal,
AgentRegistry,
AgentRole,
BlackboardRegistry,
CommunicationStyle,
CrewBridge,
CrewDispatch,
CrewTask,
DispatchResult,
FeatureAd,
FilterPhase,
// Kernel extensions (cross-platform best practices)
FilterPipeline,
GuardrailAction,
GuardrailResult,
KernelFilter,
KernelGuardrail,
KernelMemory,
KernelSession,
KernelSpan,
KernelTrace,
MemoryBank,
MemoryKind,
MessageKind,
ObservabilityManager,
Persona,
PersonaExchange,
PersonaRegistry,
PersonalityTrait,
StyleOverride,
TaskStatus,
ThinkingTemplate,
ThinkingTemplateRegistry,
VerificationEngine,
VerificationKind,
VerificationRule,
VolitionDTO,
VolitionSummary,
WorkflowNode,
WorkflowOp,
WorkflowStep,
execute_workflow,
};
// === Error types ===
/// Crate-level error type
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Storage error: {0}")]
Storage(String),
#[error("Query error: {0}")]
Query(String),
#[error("Invalid fingerprint: expected {expected} bytes, got {got}")]
InvalidFingerprint { expected: usize, got: usize },
#[error("Node not found: {0}")]
NodeNotFound(String),
#[error("Invalid inference: {0}")]
InvalidInference(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Arrow error: {0}")]
Arrow(#[from] arrow::error::ArrowError),
#[error("DataFusion error: {0}")]
DataFusion(#[from] datafusion::error::DataFusionError),
}
// StorageError conversion removed - use Error::Storage directly
impl From<query::QueryError> for Error {
fn from(e: query::QueryError) -> Self {
Error::Query(format!("{}", e)) // snafu Display includes location
}
}
#[cfg(feature = "lancedb")]
impl From<lance::Error> for Error {
fn from(e: lance::Error) -> Self {
Error::Storage(e.to_string())
}
}
pub type Result<T> = std::result::Result<T, Error>;
// === Constants ===
/// Version info
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// Fingerprint dimensions (16K = 2^14, exact u64 alignment, no partial word)
pub const FINGERPRINT_BITS: usize = 16_384;
/// Alias for `FINGERPRINT_WORDS` — kept for backwards compatibility.
/// Prefer `storage::bind_space::FINGERPRINT_WORDS` for new code.
pub const FINGERPRINT_U64: usize = crate::storage::bind_space::FINGERPRINT_WORDS;
pub const FINGERPRINT_BYTES: usize = 2048; // 256×8