Skip to main content

cognee_lib/
lib.rs

1//! Unified public API for Cognee-Rust.
2//!
3//! This crate provides a single entry point by re-exporting the core operations:
4//! - add (`AddPipeline`)
5//! - cognify (`cognify()` free function and related types)
6//! - search (`SearchBuilder`/`SearchOrchestrator` and related types)
7//!
8//! ## OpenTelemetry support
9//!
10//! Cognee emits structured spans for every pipeline stage, search retriever,
11//! and HTTP route. To export them to an OTLP collector (Grafana Tempo,
12//! Honeycomb, Dash0, in-cluster `otel-collector`, ...), enable the
13//! `telemetry` cargo feature and set `OTEL_EXPORTER_OTLP_ENDPOINT`:
14//!
15//! ```ignore
16//! use cognee_lib::telemetry::{init_telemetry, TelemetryGuard};
17//! use cognee_lib::config::{ConfigManager, Settings};
18//! use tracing_subscriber::Registry;
19//!
20//! let settings: Settings = ConfigManager::from_env().settings().clone();
21//! let (_layer, _guard) = init_telemetry::<Registry>(&settings)
22//!     .expect("telemetry init");
23//! // ... compose `_layer` onto your subscriber; spans are flushed when
24//! // `_guard` is dropped.
25//! ```
26//!
27//! See [`docs/observability/opentelemetry.md`](https://github.com/topoteretes/cognee-rs/blob/main/docs/observability/opentelemetry.md)
28//! for the full operator guide, env-var reference, and deployment recipes.
29
30/// Core pipeline orchestration primitives.
31pub mod core {
32    pub use cognee_core::*;
33}
34
35/// Data ingestion (add) pipeline.
36pub mod add {
37    pub use cognee_ingestion::{
38        AddParams, AddPipeline, ContentHasher, HashAlgorithm, IngestionError, ProcessedInput,
39        build_add_pipeline, build_add_pipeline_with_acl, generate_data_id, generate_dataset_id,
40        make_persist_data_task, make_persist_data_task_with_acl, make_process_input_task,
41        persist_data, persist_data_with_acl, process_input,
42    };
43}
44
45/// Knowledge-graph extraction (cognify) pipeline.
46pub mod cognify {
47    #[cfg(feature = "hf-tokenizer")]
48    pub use cognee_chunking::HuggingFaceTokenCounter;
49    #[cfg(feature = "tiktoken")]
50    pub use cognee_chunking::TikTokenCounter;
51    pub use cognee_chunking::{
52        ChunkingError, CutType, TokenCounter, TokenCounterKind, WordCounter,
53    };
54    pub use cognee_cognify::*;
55}
56
57/// Search pipeline and retrieval strategies.
58pub mod search {
59    pub use cognee_search::*;
60}
61
62/// Data and dataset deletion pipeline.
63pub mod delete {
64    pub use cognee_delete::*;
65}
66
67/// Core data models.
68pub mod models {
69    pub use cognee_models::*;
70}
71
72/// File storage abstraction.
73pub mod storage {
74    pub use cognee_storage::*;
75}
76
77/// Metadata database abstraction.
78pub mod database {
79    pub use cognee_database::*;
80}
81
82/// Graph database abstraction.
83pub mod graph {
84    #[cfg(feature = "ladybug")]
85    pub use cognee_graph::LadybugAdapter;
86    #[cfg(any(test, feature = "testing"))]
87    pub use cognee_graph::MockGraphDB;
88    pub use cognee_graph::{
89        EdgeData, GraphDBError, GraphDBResult, GraphDBTrait, GraphDBTraitExt, GraphEdge, GraphNode,
90        NodeData,
91    };
92}
93
94/// Vector database abstraction.
95///
96/// `BruteForceVectorDB` — pure-Rust in-memory edge/Android backend.
97pub mod vector {
98    pub use cognee_vector::BruteForceVectorDB;
99    #[cfg(feature = "testing")]
100    pub use cognee_vector::MockVectorDB;
101    #[cfg(feature = "pgvector")]
102    pub use cognee_vector::PgVectorAdapter;
103    pub use cognee_vector::{
104        CollectionConfig, DistanceMetric, SearchResult, VectorDB, VectorDBError, VectorDBResult,
105        VectorPoint,
106    };
107}
108
109/// Embedding engine abstraction and providers.
110pub mod embedding {
111    pub use cognee_embedding::utils::{
112        handle_embedding_response, is_embeddable, sanitize_embedding_inputs,
113    };
114    pub use cognee_embedding::{
115        EmbeddingConfig, EmbeddingEngine, EmbeddingError, EmbeddingProvider, EmbeddingResult,
116        MockEmbeddingEngine, OllamaEmbeddingEngine, OpenAICompatibleEmbeddingEngine,
117    };
118    #[cfg(feature = "onnx")]
119    pub use cognee_embedding::{
120        ModelUrls, OnnxEmbeddingConfig, OnnxEmbeddingEngine, download_model, ensure_model_exists,
121        ensure_tokenizer_exists,
122    };
123}
124
125/// LLM provider abstraction.
126pub mod llm {
127    pub use cognee_llm::*;
128}
129
130/// Ontology resolution.
131pub mod ontology {
132    pub use cognee_ontology::*;
133}
134
135/// Knowledge-graph visualization (requires `visualization` feature).
136#[cfg(feature = "visualization")]
137pub mod visualization {
138    pub use cognee_visualization::*;
139}
140
141#[cfg(feature = "visualization")]
142pub use cognee_visualization::{VisualizationError, visualize};
143
144#[cfg(feature = "server")]
145pub mod http {
146    //! HTTP server surface. Available only when the `server` feature is enabled.
147    //! Consumers who only need the embedded server inside their own binary should
148    //! prefer this re-export over taking a direct dependency on `cognee-http-server`,
149    //! to keep their dependency closure aligned with the rest of the cognee crates.
150    pub use cognee_http_server::*;
151}
152
153/// Session management.
154pub mod session;
155
156/// Top-level API functions mirroring the Python SDK.
157pub mod api;
158/// Component lifecycle management.
159pub mod component_manager;
160/// Runtime configuration management.
161pub mod config;
162/// Pipeline execution context.
163pub mod context;
164/// Component error types.
165pub mod error;
166
167/// Product-analytics telemetry.
168pub mod telemetry;
169
170pub use api::notebooks::{
171    NotebookError, create_notebook, delete_notebook, list_notebooks, update_notebook,
172};
173pub use api::{DatasetDb, DatasetError, DatasetManager};
174pub use component_manager::ComponentManager;
175pub use config::{ConfigError, ConfigManager, Settings};
176pub use context::PipelineContext;
177pub use error::ComponentError;
178
179/// Convenience re-exports for common usage.
180pub mod prelude {
181    pub use crate::add::AddPipeline;
182    pub use crate::api::DatasetManager;
183    pub use crate::api::{
184        ApiError, DatasetRef, ForgetResult, ForgetTarget, ImproveParams, ImproveResult,
185        PruneResult, PruneTarget, RecallItem, RecallResult, RecallSource, RememberItemInfo,
186        RememberResult, RememberStatus, UpdateResult, forget, improve, prune_data, prune_system,
187        recall, remember, update,
188    };
189    pub use crate::cognify::{CognifyConfig, cognify};
190    pub use crate::cognify::{MemifyConfig, MemifyResult, run_memify};
191    pub use crate::core::{
192        AsyncRuntime, CancellationHandle, CancellationToken, CpuPool, CpuPoolExt, ExecutionError,
193        NoopWatcher, Pipeline, PipelineWatcher, ProgressToken, RayonThreadPool, RetryDelay,
194        RetryPolicy, Task, TaskContext, TaskContextBuilder, TaskInfo, Value, execute,
195        execute_blocking, execute_in_background,
196    };
197    pub use crate::database::{AclDb, DatabaseConnection, DeleteDb, IngestDb, SearchHistoryDb};
198    pub use crate::graph::GraphDBTrait;
199    pub use crate::llm::Llm;
200    pub use crate::models::{Data, DataInput, Dataset};
201    pub use crate::search::{SearchBuilder, SearchOrchestrator, SearchRequest, SearchType};
202    pub use crate::storage::{LocalStorage, StorageTrait};
203    pub use crate::vector::VectorDB;
204    pub use uuid::Uuid;
205}
206
207pub use add::{
208    AddParams, AddPipeline, ContentHasher, ProcessedInput, build_add_pipeline, generate_dataset_id,
209    make_persist_data_task, make_process_input_task, persist_data, process_input,
210};
211
212pub use cognee_core;
213pub use cognee_database;
214pub use cognee_delete;
215pub use cognee_embedding;
216pub use cognee_graph;
217pub use cognee_llm;
218pub use cognee_models;
219pub use cognee_ontology;
220pub use cognee_session;
221pub use cognee_storage;
222pub use cognee_vector;
223pub use uuid;