How dto-btn/enterprise-knowledge-hub works
Purpose and entry points
Enterprise Knowledge Hub is a FastAPI service that ingests local knowledge-base content, creates embeddings, stores vectorized records in PostgreSQL/pgvector, and exposes search and run-management APIs. main.py boots the API, migrations, queue/worker integration, and configurable cron jobs. A small developer status UI is served by router/frontend/frontend.py.
API and run orchestration
The root router separates retrieval from ingestion/run control:
• router/root/search_retrieve_endpoints.py provides knowledge search/retrieval over stored vectors.
• router/root/run_management_endpoints.py creates, updates, deletes, and indexes processing runs.
• router/root/run_state.py tracks in-process indexing state; durable run records are handled through repository/run_history.py and services/database/run_history_service.py.
Knowledge ingestion pipeline
Knowledge providers implement a common ingestion model in services/knowledge/base.py and shared item models in services/knowledge/models.py. The primary implementation parses local Wikipedia content from content/wikipedia through services/knowledge/wikipedia/wikipedia.py; policy content is supported by services/knowledge/tbs_policies/tbs_policies.py. services/knowledge/batch_handler.py batches items to bound embedding and queue overhead. Content acquisition/update scheduling belongs behind services/content_scraper/base_cronjob.py.
Asynchronous queue boundary
Index work is decoupled through a queue abstraction:
• provider/queue/base.py defines the provider contract.
• provider/queue/rabbitmq.py implements RabbitMQ transport.
• services/queue/queue_service.py publishes/consumes work, while services/queue/queue_worker.py executes queued processing.
This boundary allows API-triggered runs and cron-triggered ingestion to hand off expensive embedding/indexing work without coupling request handling to model execution.
Embedding subsystem
Embedding is provider-based, with provider/embedding/base.py defining the interface and provider/embedding/qwen3/embedder_factory.py selecting a runtime backend. provider/embedding/qwen3/sentence_transformer.py uses Sentence Transformers, with CPU-friendly MiniLM and GPU/CUDA-capable Qwen configurations controlled by environment. Embedding dimensions must match the pgvector field defined in repository/knowledge_wikipedia_model.py; this is a critical schema/model compatibility boundary.
Persistence and data model
Peewee-backed repositories isolate PostgreSQL access: repository/database.py establishes database integration, repository/knowledge_wikipedia.py persists and searches Wikipedia vectors, and repository/kb_source_registry.py records source metadata. Models in repository/knowledge_wikipedia_model.py, repository/run_history_model.py, and related policy/source models define durable tables. repository/migration/run_migrations.py applies initial schema evolution, while deployments/ekh/sql/00_init_pgvector.sql enables vector support.
Runtime and deployment
Local Docker Compose provisions the FastAPI service, PostgreSQL/pgvector, RabbitMQ, and pgAdmin via docker-compose.yml; docker-compose.gpu.yml raises resources for L40 GPU workloads. Container packaging is in Dockerfile. Kubernetes deployment is Helm-based under deployments/ekh/templates/deployment.yaml, with Argo CD applications in deployments/argocd/application.yaml. Corporate TLS certificates are bundled under certs/ for outbound content/model requests where required.
Main entry points: main.py FastAPI bootstrap · queue_service.py Queue service · run_management_endpoints.py Run management API · wikipedia.py Wikipedia provider
Components 23
API & Control
- FastAPI bootstrap · Boots API, migrations, workers, and cron jobs.
main.py - Search API
router/root/search_retrieve_endpoints.py - Run management API
router/root/run_management_endpoints.py - In-process run state
router/root/run_state.py - Developer status UI
router/frontend/frontend.py
Ingestion Pipeline
- Knowledge provider contract · Shared provider model and item types.
services/knowledge/base.py - Wikipedia provider · Parses local Wikipedia content.
services/knowledge/wikipedia/wikipedia.py - Policy provider
services/knowledge/tbs_policies/tbs_policies.py - Local content volume · Runtime-mounted local Wikipedia corpus.
content - Knowledge batcher · Bounds embedding and queue overhead.
services/knowledge/batch_handler.py - Content update scheduler
services/content_scraper/base_cronjob.py
Async Processing
- Queue contract
provider/queue/base.py - RabbitMQ transport
provider/queue/rabbitmq.py - Queue service · Publishes and consumes indexing work.
services/queue/queue_service.py - Indexing worker · Executes queued embedding and indexing.
services/queue/queue_worker.py - Qwen embedding factory · Selects CPU or CUDA embedding runtime.
provider/embedding/qwen3/embedder_factory.py - Sentence Transformer runtime · MiniLM CPU and Qwen GPU/CUDA configurations.
provider/embedding/qwen3/sentence_transformer.py
Persistence
- Wikipedia vector repository · Persists and searches knowledge vectors.
repository/knowledge_wikipedia.py - Vector table schema · Embedding dimensions must match the runtime output.
repository/knowledge_wikipedia_model.py - Durable run history
repository/run_history.py - Schema migrations
repository/migration/run_migrations.py
Runtime & Deployment
- Local Compose stack · Provisions API, PostgreSQL/pgvector, RabbitMQ, and pgAdmin.
docker-compose.yml - Helm deployment
deployments/ekh/templates/deployment.yaml
Connections 27
- FastAPI bootstrap → Search API: serves
- FastAPI bootstrap → Run management API: serves
- FastAPI bootstrap → Developer status UI: serves
- FastAPI bootstrap → Schema migrations: runs at startup
- Run management API → In-process run state: tracks active run
- Run management API → Durable run history: records run
- Run management API → Queue service: starts indexing
- Search API → Wikipedia vector repository: vector search
- Local content volume → Wikipedia provider: parsed by
- Wikipedia provider → Knowledge provider contract: implements
- Policy provider → Knowledge provider contract: implements
- Wikipedia provider → Knowledge batcher: emits items
- Policy provider → Knowledge batcher: emits items
- Content update scheduler → Queue service: schedules ingestion
- Knowledge batcher → Queue service: enqueues batches
- Queue service → Queue contract: uses
- Queue contract → RabbitMQ transport: implemented by
- Queue service → Indexing worker: dispatches work
- Indexing worker → Qwen embedding factory: creates embedder
- Qwen embedding factory → Sentence Transformer runtime: selects backend
- Indexing worker → Wikipedia vector repository: writes vectors
- Wikipedia vector repository → Vector table schema: maps records
- Sentence Transformer runtime → Vector table schema: dimension compatible
- Schema migrations → Vector table schema: creates schema
- Local Compose stack → FastAPI bootstrap: runs locally
- Local Compose stack → RabbitMQ transport: provisions broker
- Helm deployment → FastAPI bootstrap: deploys