# starlightsearch/embedanything architecture

> Architecture diagram of the GitHub repository starlightsearch/embedanything, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/starlightsearch/embedanything
- Repository: https://github.com/starlightsearch/embedanything

## Overview

##### Project Type and Purpose
- This is a multi‐language, open‐source embedding pipeline and SDK (“EmbedAnything”) that provides:
- A core Rust library for ingestion, chunking, model inference, and streaming embeddings
- Python bindings (via pyo3) for easy consumption in Python
- A standalone Rust HTTP server (and Docker images) exposing embedding-as-a-service
- Numerous example scripts and adapters for vector databases
- Its goal is to take arbitrary files (text, PDF, image, audio, web pages), chunk them, run high‐performance embedding models (ONNX, Candle, cloud), and stream results into vector stores.

##### File Structure Analysis & Architectural Patterns
- Top‐Level Modules:
─ /rust        – Core embedding engine (chunkers, embeddings, file loaders, models, MPSC streaming)
─ /processors  – Specialized file processors (docx, markdown, HTML, PDF with Tesseract)
─ /python      – Python package with pyo3 bindings exposing core Rust functionality
─ /server      – Rust HTTP server exposing REST/gRPC embedding endpoints
─ /examples    – Sample scripts driving ingestion→embedding→vector DB indexing
─ /docs        – MkDocs site content and blog posts
- Patterns:
─ Pipeline / Streaming pattern: document ingestion → chunking → embedding → dispatch to vector DB adapter
─ Modular crates for each concern (chunkers, embeddings, file_processor, s3_loader)
─ MPSC channels (Rust multi‐producer, single‐consumer) for concurrent vector streaming
─ Adapter strategy pattern for pluggable vector DB targets (Weaviate, Pinecone, Qdrant, etc.)

##### README Insights
- Highlights multi‐threaded “vector streaming” to decouple file processing from inference
- Lists supported embedding backends: Candle, ONNX, cloud APIs
- Mentions Docker artifacts: embedanything-server, release Dockerfile, CI workflows

##### Diagramming the Architecture
a. Main Components:
1. Client Layer
- Python SDK (embed_anything package)
- CLI / example scripts
- HTTP/REST clients talking to the server
2. Core Engine (Rust Crates)
- File Loader & S3 Loader
- File Processors (docx, PDF/Tesseract, markdown, HTML, audio)
- Chunkers (sentence, semantic, late-chunking)
- Embedding Backends (Local Candle, ONNX runtime, Cloud APIs)
- Streaming Module (MPSC channels)
3. Adapter Layer
- Vector DB Adapters (Elastic, Weaviate, Pinecone, Qdrant, Milvus, Chroma, etc.)
4. Persistence & External Services
- External Vector DBs
- S3 / cloud storage sources
5. HTTP Server
- REST/gRPC endpoints wrapping Core Engine + Adapters

b. Relationships & Interactions:
- Python SDK or CLI calls into Rust core (via pyo3) OR sends HTTP requests to the server
- Core Engine ingests files → File Processor → Chunker → Embedding Backend
- Embeddings emitted over channels to Adapter layer
- Adapter writes embeddings into vector database
- Server orchestrates the same pipeline upon HTTP requests

c. Architectural Patterns & Principles:
- Single Responsibility per crate
- Concurrent pipeline with Rust MPSC channels
- Strategy pattern for embedding backends & DB adapters
- Clear separation: ingestion, processing, inference, persistence
- Language boundary: Rust for performance, Python for usability

d. Technologies & Frameworks:
- Rust crates (tokio, pyo3, onnxruntime, candle)
- Python packaging (pyproject.toml, pip install)
- Docker for containerization (Dockerfile, server.Dockerfile, release.Dockerfile)
- CI/CD via GitHub Actions (CI.yml, docs.yml)
- MkDocs for documentation (mkdocs.yml)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        PythonSDK["Python SDK (pyo3)"]:::client
        CLI["CLI / Example Scripts"]:::client
        HTTPClient["HTTP/REST Client"]:::client
    end

    %% HTTP Server
    HTTPServer["Rust HTTP Server (REST/gRPC)"]:::server

    %% Core Engine
    subgraph "Core Engine (Rust Crates)"
        direction TB
        CoreLib["Core Library"]:::core
        FileLoader["File Loader"]:::core
        S3Loader["S3 Loader"]:::core
        FileProcessors["File Processors"]:::core
        Chunkers["Chunkers"]:::core
        Embeddings["Embedding Backends"]:::core
        Streaming["Streaming Module (MPSC)"]:::core
    end

    %% Adapter Layer
    subgraph "Adapter Layer"
        direction TB
        Adapters["Vector DB Adapters"]:::adapter
    end

    %% External Services
    subgraph "External Services"
        direction TB
        VectorDB["Vector Databases"]:::external
        S3["S3 / Cloud Storage"]:::external
    end

    %% Connections - Client to Engine/Server
    PythonSDK -->|pyo3 FFI| CoreLib
    CLI -->|invokes Rust Core| CoreLib
    CLI -->|uses adapters| Adapters
    HTTPClient -->|HTTP/gRPC| HTTPServer
    HTTPServer -->|orchestrates pipeline| CoreLib

    %% Core Pipeline Flow
    CoreLib --> FileLoader
    CoreLib --> S3Loader
    FileLoader --> FileProcessors
    S3Loader --> FileProcessors
    FileProcessors --> Chunkers
    Chunkers --> Embeddings
    Embeddings --> Streaming
    Streaming --> Adapters
    Adapters --> VectorDB
    S3 -->|stores source files| S3Loader

    %% Click Events
    click PythonSDK "https://github.com/starlightsearch/embedanything/blob/main/python/src/lib.rs"
    click FileLoader "https://github.com/starlightsearch/embedanything/blob/main/rust/src/file_loader.rs"
    click S3Loader "https://github.com/starlightsearch/embedanything/blob/main/rust/src/s3_loader.rs"
    click FileProcessors "https://github.com/starlightsearch/embedanything/tree/main/rust/src/file_processor"
    click Chunkers "https://github.com/starlightsearch/embedanything/tree/main/rust/src/chunkers"
    click Embeddings "https://github.com/starlightsearch/embedanything/tree/main/rust/src/embeddings"
    click CoreLib "https://github.com/starlightsearch/embedanything/blob/main/rust/src/lib.rs"
    click HTTPServer "https://github.com/starlightsearch/embedanything/blob/main/server/src/main.rs"
    click Adapters "https://github.com/starlightsearch/embedanything/tree/main/examples/adapters"
    click VectorDB "https://github.com/starlightsearch/embedanything/blob/main/examples/adapters/pinecone_db.py"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef core fill:#E6F4EA,stroke:#28A745,color:#28A745;
    classDef adapter fill:#FFF4E5,stroke:#FF8C00,color:#FF8C00;
    classDef external fill:#F3E8FF,stroke:#6F42C1,color:#6F42C1;
    classDef server fill:#FFECEF,stroke:#D73A49,color:#D73A49;
```
