How aravindg-atwork/knowledge-os works
Purpose and entry points
Enterprise Knowledge Hub AI is a workspace-scoped knowledge/RAG system. It ingests Google Drive and Gmail content, indexes it, and serves permission-aware chat with source citations and document viewing. Backend entry point: backend/app/main.py; API composition: backend/app/api/v1/router.py. The React SPA starts at frontend/src/main.tsx and routes through frontend/src/app/routes.tsx.
API, identity, and tenancy boundary
FastAPI exposes auth, workspace, invitation, connector, document, and chat endpoints. Authentication/token handling and dependency-based request authorization sit at backend/app/api/deps.py, backend/app/api/v1/auth.py, and backend/app/core/security.py. Workspace membership, roles, and isolation are modeled and enforced through backend/app/models/workspace.py, backend/app/services/tenancy_service.py, and backend/app/services/document_access_service.py; this scope must propagate into repository and vector retrieval operations.
Workspace-facing frontend
The SPA owns session state and protected-route behavior in frontend/src/app/AuthContext.tsx, frontend/src/app/guards.tsx, and frontend/src/app/AppShell.tsx. Feature pages call the backend through API modules: chat (frontend/src/features/chat/ChatPage.tsx), documents (frontend/src/features/documents/DocumentListPage.tsx), and workspace/member settings (frontend/src/features/settings/WorkspaceSettingsPage.tsx). frontend/src/components/WorkspaceSwitcher.tsx makes workspace context explicit in the client.
Connectors and synchronization
A connector registry and common interface separate sync orchestration from provider implementations: backend/app/connectors/base.py, backend/app/connectors/registry.py, and backend/app/connectors/types.py. Google Drive and Gmail each support mock fixture-backed and real OAuth/API clients under backend/app/connectors/google_drive/connector.py, backend/app/connectors/gmail/connector.py, and backend/app/connectors/google_oauth.py. Sync state and change detection persist through backend/app/models/sync_state.py and backend/app/services/sync_service.py.
Asynchronous ingestion pipeline
Connector sync work is dispatched through Celery, separating API/OAuth requests from potentially expensive fetch and indexing jobs: backend/app/workers/celery_app.py, backend/app/workers/tasks_sync.py, and backend/app/workers/tasks_ingestion.py. The pipeline extracts source bytes/text, chunks normalized content, computes checksums/version behavior, embeds chunks, and writes vectors: backend/app/pipeline/pipeline_service.py, backend/app/pipeline/extractors/, and backend/app/pipeline/chunking/recursive_chunker.py. Documents and chunks remain relational records in backend/app/models/document.py and backend/app/models/chunk.py.
Retrieval and answer generation
Chat requests flow from backend/app/api/v1/chat.py into RAG/retrieval services. backend/app/services/rag_service.py coordinates query embedding, permission-filtered vector search, LLM answer generation, and citations; backend/app/services/retrieval_service.py constructs retrieval results. Vector-store abstraction and Qdrant implementation are in backend/app/vectorstore/base.py, backend/app/vectorstore/qdrant_store.py, and backend/app/vectorstore/payload_schema.py, where workspace/access metadata forms the critical search boundary.
Providers and runtime infrastructure
AI providers are selected through backend/app/ai/factory.py: local Ollama or Mistral for LLMs (backend/app/ai/llm/ollama_llm.py, backend/app/ai/llm/mistral_llm.py), with local sentence-transformer or Ollama embeddings. PostgreSQL is the system of record via SQLAlchemy/Alembic (backend/app/db/session.py, backend/app/db/migrations/); Qdrant stores vectors; Redis brokers Celery tasks; Ollama runs local models. Service topology is defined by docker-compose.yml, with development overrides in docker-compose.dev.yml; production controls are documented in docs/PRODUCTION.md.
Main entry points: pipeline_service.py Ingestion pipeline · docker-compose.yml Container topology · router.py API endpoints · sync_service.py Sync state & orchestration
Components 21
Workspace SPA
- React SPA · Workspace-scoped user interface.
frontend/src/main.tsx - Session & route guards · Maintains session and protected workspace routes.
frontend/src/app/AuthContext.tsx - Workspace UI · Chat, documents, settings, and workspace switching.
frontend/src/components/WorkspaceSwitcher.tsx
Backend API & Tenancy
- FastAPI application · Composes versioned workspace APIs.
backend/app/main.py - Auth & request authorization · Token handling and dependency-based authorization.
backend/app/api/deps.py - Workspace tenancy · Enforces membership, roles, and document access scope.
backend/app/services/tenancy_service.py - API endpoints · Auth, workspace, connector, document, and chat routes.
backend/app/api/v1/router.py
Connector Sync & Ingestion
- Connector registry · Selects provider implementations for sync.
backend/app/connectors/registry.py - Google Drive & Gmail · OAuth/API and fixture-backed source clients.
backend/app/connectors/google_drive/connector.py - Sync state & orchestration · Tracks source changes and dispatches sync work.
backend/app/services/sync_service.py - Celery sync & ingestion workers · Runs expensive fetch and indexing jobs.
backend/app/workers/tasks_sync.py - Ingestion pipeline · Extracts, chunks, versions, embeds, and indexes content.
backend/app/pipeline/pipeline_service.py
Retrieval & AI
- RAG orchestration · Generates answers and citations from scoped retrieval.
backend/app/services/rag_service.py - Permission-filtered retrieval · Builds scoped vector retrieval results.
backend/app/services/retrieval_service.py - Qdrant vector store · Applies workspace and access metadata during search.
backend/app/vectorstore/qdrant_store.py - LLM & embedding providers · Selects local or hosted generation and embedding providers.
backend/app/ai/factory.py
Data & Runtime
- PostgreSQL · Stores workspace, sync, document, and chunk records.
backend/app/db/session.py - Qdrant
- Redis
- Ollama
- Container topology · Defines local service composition.
docker-compose.yml
Connections 28
- React SPA → Session & route guards: initializes
- Session & route guards → Workspace UI: protects
- Workspace UI → FastAPI application: calls workspace APIs
- FastAPI application → API endpoints: mounts
- API endpoints → Auth & request authorization: authorizes requests
- Auth & request authorization → Workspace tenancy: resolves workspace scope
- API endpoints → Sync state & orchestration: starts connector sync
- API endpoints → RAG orchestration: sends chat requests
- Workspace tenancy → PostgreSQL: checks memberships and access
- Sync state & orchestration → Connector registry: orchestrates provider sync
- Connector registry → Google Drive & Gmail: selects
- Sync state & orchestration → Celery sync & ingestion workers: dispatches jobs
- Celery sync & ingestion workers → Redis: uses broker
- Celery sync & ingestion workers → Ingestion pipeline: runs indexing
- Google Drive & Gmail → Ingestion pipeline: supplies source content
- Ingestion pipeline → PostgreSQL: writes documents and chunks
- Ingestion pipeline → LLM & embedding providers: requests embeddings
- Ingestion pipeline → Qdrant vector store: indexes vectors
- RAG orchestration → Permission-filtered retrieval: retrieves context
- Permission-filtered retrieval → Workspace tenancy: applies access scope
- Permission-filtered retrieval → Qdrant vector store: searches scoped vectors
- Qdrant vector store → Qdrant: reads and writes
- RAG orchestration → LLM & embedding providers: embeds queries and generates answers
- LLM & embedding providers → Ollama: uses local models
- Container topology → PostgreSQL: runs
- Container topology → Qdrant: runs
- Container topology → Redis: runs
- Container topology → Ollama: runs