Connector

Trait Connector 

Source
pub trait Connector: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn scan<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SourceItem>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn connector_type(&self) -> &str { ... }
    fn source_label(&self) -> String { ... }
}
Expand description

A data source connector that produces documents for ingestion.

Implement this trait to create a custom connector in Rust. The connector is responsible for scanning an external data source and returning a list of SourceItems that flow through the standard ingestion pipeline (normalization → chunking → embedding).

§Lifecycle

  1. The connector is registered via ConnectorRegistry::register.
  2. scan is called during ctx sync custom:<name>.
  3. Returned items are normalized, chunked, and indexed.

§Example

use async_trait::async_trait;
use anyhow::Result;
use context_harness::models::SourceItem;
use context_harness::traits::Connector;
use chrono::Utc;

pub struct DatabaseConnector {
    connection_string: String,
}

#[async_trait]
impl Connector for DatabaseConnector {
    fn name(&self) -> &str { "database" }
    fn description(&self) -> &str { "Ingest rows from a database table" }
    fn connector_type(&self) -> &str { "custom" }

    async fn scan(&self) -> Result<Vec<SourceItem>> {
        // ... query database and return SourceItems
        Ok(vec![])
    }
}

Required Methods§

Source

fn name(&self) -> &str

Returns the connector instance name (e.g. "docs", "platform").

Combined with connector_type to form the source label: "{type}:{name}".

Source

fn description(&self) -> &str

Returns a one-line description of what this connector does.

Used in ctx sources output and documentation.

Source

fn scan<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<SourceItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Scan the data source and return all items to ingest.

Called on the tokio async runtime. May perform I/O operations (HTTP requests, database queries, file reads).

§Returns

A vector of SourceItems. Each item flows through the standard ingestion pipeline. Items with empty body or source_id are skipped with a warning.

Provided Methods§

Source

fn connector_type(&self) -> &str

Returns the connector type identifier (e.g. "filesystem", "git", "s3", "custom").

Built-in connectors return their type name; custom (user-defined) connectors default to "custom".

Source

fn source_label(&self) -> String

Returns the source label used to tag documents from this connector.

Defaults to "{connector_type}:{name}" (e.g. "git:platform").

Implementors§