Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ arrow-schema = "50"
datafusion = "35"
sqlparser = "0.43"

# Async
tokio = { version = "1.35", features = ["full"] }
futures = "0.3"

# Parallelism
rayon = { version = "1.8", optional = true }
parking_lot = "0.12"
Expand All @@ -44,6 +48,8 @@ thiserror = "1.0"
uuid = { version = "1.6", features = ["v4"] }
hashbrown = "0.14"
smallvec = "1.11"
chrono = "0.4"
hex = "0.4"

# Python
pyo3 = { version = "0.20", optional = true, features = ["extension-module"] }
Expand Down
9 changes: 9 additions & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ pub use buffer::BufferPool;

/// Dense embedding vector
pub type Embedding = Vec<f32>;

/// Fingerprint dimension in bits (10K VSA standard)
pub const DIM: usize = 10_000;

/// Fingerprint dimension in u64 words
pub const DIM_U64: usize = 157; // ceil(10000/64)

/// Last word mask for 10K bits (only 16 bits used in last u64)
pub const LAST_MASK: u64 = (1 << 16) - 1;
94 changes: 63 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,48 @@
//!
//! ## Quick Start
//!
//! ```rust
//! use ladybug::{Database, Thought};
//! ```rust,ignore
//! use ladybug::{Database, Thought, NodeRecord, cypher_to_sql};
//!
//! // Open database
//! let db = Database::open("./mydb")?;
//! let db = Database::open("./mydb").await?;
//!
//! // Conventional: SQL
//! let results = db.sql("SELECT * FROM thoughts WHERE confidence > 0.7")?;
//! // SQL queries (via DataFusion)
//! let results = db.sql("SELECT * FROM nodes WHERE label = 'Thought'").await?;
//!
//! // Conventional: Vector search
//! let similar = db.vector_search(&embedding, 10)?;
//! // Cypher queries (auto-transpiled to recursive CTEs)
//! let paths = db.cypher("MATCH (a)-[:CAUSES*1..5]->(b) RETURN b").await?;
//!
//! // AGI: Resonance (Hamming similarity on 10K-bit fingerprints)
//! let resonant = db.resonate(&fingerprint, 0.7)?;
//! // Vector search (via LanceDB ANN)
//! let similar = db.vector_search(&embedding, 10).await?;
//!
//! // AGI: Graph traversal with amplification
//! let chains = db.query()
//! .from("config_change")
//! .causes()
//! .amplifies(2.0)
//! .depth(1..=5)
//! .execute()?;
//! // Resonance search (Hamming similarity on 10K-bit fingerprints)
//! let resonant = db.resonate(&fingerprint, 0.7, 10);
//!
//! // AGI: Counterfactual reasoning
//! let what_if = db.fork()
//! .apply(|w| w.remove("feature_flag"))
//! .propagate()
//! .diff()?;
//! // Butterfly detection (causal amplification chains)
//! let butterflies = db.detect_butterflies("change_id", 5.0, 10).await?;
//!
//! // AGI: NARS inference
//! let conclusion = premise1.infer::<Deduction>(&premise2)?;
//! // Counterfactual reasoning
//! let forked = db.fork();
//! ```
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ LADYBUGDB │
//! ├─────────────────────────────────────────────────────────────────┤
//! │ │
//! │ 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) │
//! │ │
//! └─────────────────────────────────────────────────────────────────┘
//! ```

#![cfg_attr(feature = "simd", feature(portable_simd))]
Expand All @@ -55,22 +66,22 @@ pub mod fabric;
pub mod python;

// Re-exports for convenience
pub use crate::core::{Fingerprint, Embedding, VsaOps};
pub use crate::core::{Fingerprint, Embedding, VsaOps, DIM, DIM_U64};
pub use crate::cognitive::{Thought, Concept, Belief, ThinkingStyle};
pub use crate::nars::{TruthValue, Evidence, Deduction, Induction, Abduction};
pub use crate::graph::{Edge, EdgeType, Traversal};
pub use crate::world::{World, Counterfactual, Change};
pub use crate::query::{Query, QueryResult};
pub use crate::storage::Database;
pub use crate::query::{Query, QueryResult, cypher_to_sql, SqlEngine, QueryBuilder};
pub use crate::storage::{Database, LanceStore, NodeRecord, EdgeRecord};

/// Crate-level error type
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Storage error: {0}")]
Storage(#[from] storage::StorageError),
Storage(String),

#[error("Query error: {0}")]
Query(#[from] query::QueryError),
Query(String),

#[error("Invalid fingerprint: expected {expected} bytes, got {got}")]
InvalidFingerprint { expected: usize, got: usize },
Expand All @@ -83,6 +94,30 @@ pub enum Error {

#[error("IO error: {0}")]
Io(#[from] std::io::Error),

#[error("Lance error: {0}")]
Lance(#[from] lance::Error),

#[error("Arrow error: {0}")]
Arrow(#[from] arrow::error::ArrowError),

#[error("DataFusion error: {0}")]
DataFusion(#[from] datafusion::error::DataFusionError),

#[error("Tokio error: {0}")]
Tokio(#[from] tokio::io::Error),
}

impl From<storage::StorageError> for Error {
fn from(e: storage::StorageError) -> Self {
Error::Storage(e.to_string())
}
}

impl From<query::QueryError> for Error {
fn from(e: query::QueryError) -> Self {
Error::Query(e.to_string())
}
}

pub type Result<T> = std::result::Result<T, Error>;
Expand All @@ -94,6 +129,3 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const FINGERPRINT_BITS: usize = 10_000;
pub const FINGERPRINT_U64: usize = 157; // ceil(10000/64)
pub const FINGERPRINT_BYTES: usize = FINGERPRINT_U64 * 8;

/// Default embedding dimension (for dense vectors)
pub const EMBEDDING_DIM: usize = 1024;
Loading