Skip to main content

cognee_lib/
context.rs

1//! Pipeline context trait for shared component access.
2
3use std::sync::Arc;
4
5use async_trait::async_trait;
6
7use cognee_database::DatabaseConnection;
8use cognee_embedding::EmbeddingEngine;
9use cognee_graph::GraphDBTrait;
10use cognee_llm::Llm;
11use cognee_storage::StorageTrait;
12use cognee_vector::VectorDB;
13
14use crate::error::ComponentError;
15
16/// Trait providing access to shared pipeline components.
17///
18/// Implementations lazily initialize and cache expensive components
19/// (e.g., embedding models, database connections) so they can be
20/// reused across multiple pipeline invocations.
21#[async_trait]
22pub trait PipelineContext: Send + Sync {
23    async fn storage(&self) -> Result<Arc<dyn StorageTrait>, ComponentError>;
24    async fn database(&self) -> Result<Arc<DatabaseConnection>, ComponentError>;
25    async fn graph_db(&self) -> Result<Arc<dyn GraphDBTrait>, ComponentError>;
26    async fn vector_db(&self) -> Result<Arc<dyn VectorDB>, ComponentError>;
27    async fn embedding_engine(&self) -> Result<Arc<dyn EmbeddingEngine>, ComponentError>;
28    async fn llm(&self) -> Result<Arc<dyn Llm>, ComponentError>;
29}