Skip to content
GitHubDiscord

AI Workers (lexigram-ai-workers)

AI background workers for the Lexigram Framework — batch embedding, document ingestion, DLQ, maintenance


AI background workers for the Lexigram Framework. Handles the heavy-lifting off the request path: document ingestion, batch embedding generation, periodic maintenance, and dead-letter-queue recovery — all with progress tracking, exponential backoff, and health reporting. Zero-config usage starts with sensible defaults.

Terminal window
uv add lexigram-ai-workers
from lexigram import Application
from lexigram.di.module import Module, module
from lexigram.ai.workers import WorkersModule
from lexigram.ai.workers.config import WorkersConfig
@module(imports=[
WorkersModule.configure(
WorkersConfig(
batch_embedding_concurrency=3,
document_ingestion_concurrency=3,
enable_maintenance=True,
dlq_check_interval=60,
)
)
])
class AppModule(Module):
pass
app = Application(modules=[AppModule])
if __name__ == "__main__":
app.run()

Zero-config usage: Call WorkersModule.configure() with no arguments to use defaults.

application.yaml
ai_workers:
enabled: true
batch_embedding_concurrency: 3
document_ingestion_concurrency: 3
enable_maintenance: true
dlq_check_interval: 60
Section titled “Option 2 — Profiles + Environment Variables (recommended)”
Terminal window
export LEX_AI_WORKERS__BATCH_EMBEDDING_CONCURRENCY=5
# Environment variables for each field
from lexigram.ai.workers.config import WorkersConfig
from lexigram.ai.workers import WorkersModule
config = WorkersConfig(
enabled=True,
batch_embedding_concurrency=5,
document_ingestion_concurrency=3,
enable_maintenance=True,
dlq_check_interval=60,
)
WorkersModule.configure(config)
FieldDefaultEnv varDescription
enabledTrueLEX_AI_WORKERS__ENABLEDMaster on/off switch for all background workers
batch_embedding_concurrency3LEX_AI_WORKERS__BATCH_EMBEDDING_CONCURRENCYConcurrent embedding batch tasks
document_ingestion_concurrency3LEX_AI_WORKERS__DOCUMENT_INGESTION_CONCURRENCYConcurrent document processing tasks
enable_maintenanceTrueLEX_AI_WORKERS__ENABLE_MAINTENANCEEnable vector-store and cache maintenance
dlq_check_interval60LEX_AI_WORKERS__DLQ_CHECK_INTERVALSeconds between DLQ recovery sweeps
MethodDescription
WorkersModule.configure(config, enable_scheduler)Configure with explicit config
WorkersModule.stub(config)Minimal config for testing
  • Document ingestion worker: Parse PDF, DOCX, TXT, HTML, Markdown into chunks for vector store
  • Batch embedding worker: Process chunks in configurable batches with in-memory embedding cache
  • Dead letter queue worker: Handle failed jobs with failure classification and exponential backoff
  • Maintenance worker: Periodic vector store index optimization, cache cleanup, document cleanup
  • Progress tracking: Job progress monitoring with cache hit rate statistics
  • Adapters: RAGAdapter, TasksAdapter, LoaderWorker for ecosystem integration
async with Application.boot(modules=[WorkersModule.stub()]) as app:
# your test code
...
FileWhat it contains
src/lexigram/ai/workers/module.pyWorkersModule.configure(), .stub()
src/lexigram/ai/workers/config.pyWorkersConfig
src/lexigram/ai/workers/document_ingestion/worker.pyDocumentIngestionWorker
src/lexigram/ai/workers/batch_embedding/worker.pyBatchEmbeddingWorker
src/lexigram/ai/workers/dlq/worker.pyDeadLetterQueueWorker
src/lexigram/ai/workers/maintenance/worker.pyMaintenanceWorker
src/lexigram/ai/workers/types.pyDLQItem, DLQStats, MaintenanceTask, MaintenanceResult
src/lexigram/ai/workers/di/provider.pyWorkersProvider