Skip to main content

lexigram-ai-workers

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


Overview

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.

Full documentation: docs.lexigram.dev

Install

uv add lexigram-ai-workers

Quick Start

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


async with Application.boot(modules=[AppModule]) as app:
    # use app.container to resolve services
    ...

Configuration

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

Option 1 — YAML file

# application.yaml
ai_workers:
  enabled: true
  batch_embedding_concurrency: 3
  document_ingestion_concurrency: 3
  enable_maintenance: true
  dlq_check_interval: 60

Option 2 — Profiles + Environment Variables (recommended)

export LEX_AI_WORKERS__BATCH_EMBEDDING_CONCURRENCY=5
# Environment variables for each field

Option 3 — Python

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)

Config reference

Field Default Env var Description
enabled True LEX_AI_WORKERS__ENABLED Master on/off switch for all background workers
batch_embedding_concurrency 3 LEX_AI_WORKERS__BATCH_EMBEDDING_CONCURRENCY Concurrent embedding batch tasks
document_ingestion_concurrency 3 LEX_AI_WORKERS__DOCUMENT_INGESTION_CONCURRENCY Concurrent document processing tasks
enable_maintenance True LEX_AI_WORKERS__ENABLE_MAINTENANCE Enable vector-store and cache maintenance
dlq_check_interval 60 LEX_AI_WORKERS__DLQ_CHECK_INTERVAL Seconds between DLQ recovery sweeps

Securing document ingestion (path-traversal control)

When a document source path can be influenced by users (an upload filename, an API parameter), constrain it with allowed_root. Both the worker and the underlying parser accept the same opt-in argument:

from pathlib import Path
from lexigram.ai.workers.document_ingestion import DocumentIngestionWorker

worker = DocumentIngestionWorker(
    vector_store=store,
    queue=queue,
    allowed_root=Path("/srv/app/documents"),
)

With allowed_root set, every ingested source is resolved — symlinks and .. segments followed — and must land inside that directory, otherwise the job fails with RAGError. The default (allowed_root=None) performs no containment and preserves historical behavior, which is appropriate when all sources are fully trusted server-local files. A custom document_parser passed to the worker is responsible for its own path policy; allowed_root only applies to the built-in UniversalDocumentParser the worker constructs. The same check applies to UniversalDocumentParser.parse() and UniversalDocumentParser.extract_metadata() when the parser is used directly, and to LoaderWorkerBridge sources (the bridge submits to the worker, so configure allowed_root on the worker).

Module Factory Methods

Method Description
WorkersModule.configure(config, enable_scheduler) Configure with explicit config
WorkersModule.stub(config) Minimal config for testing

Key Features

  • 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

Testing

async with Application.boot(modules=[WorkersModule.stub()]) as app:
    # your test code
    ...

Key Source Files

File What it contains
src/lexigram/ai/workers/module.py WorkersModule.configure(), .stub()
src/lexigram/ai/workers/config.py WorkersConfig
src/lexigram/ai/workers/document_ingestion/worker.py DocumentIngestionWorker
src/lexigram/ai/workers/batch_embedding/worker.py BatchEmbeddingWorker
src/lexigram/ai/workers/dlq/worker.py DeadLetterQueueWorker
src/lexigram/ai/workers/maintenance/worker.py MaintenanceWorker
src/lexigram/ai/workers/types.py DLQItem, DLQStats, MaintenanceTask, MaintenanceResult
src/lexigram/ai/workers/di/provider.py WorkersProvider

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lexigram_ai_workers-0.1.5003.tar.gz (69.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lexigram_ai_workers-0.1.5003-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_ai_workers-0.1.5003.tar.gz.

File metadata

File hashes

Hashes for lexigram_ai_workers-0.1.5003.tar.gz
Algorithm Hash digest
SHA256 d33b7af572c8b8163e597e810c000f0ddaeeb8010f158b23e3a9ac4fc195b8b6
MD5 2801a7d2a6f1b0b8b3421ded64862472
BLAKE2b-256 31a20e57fac2840bc67abf7d73e401ba070b4e4918989d35e09be03a97de6144

See more details on using hashes here.

File details

Details for the file lexigram_ai_workers-0.1.5003-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_ai_workers-0.1.5003-py3-none-any.whl
Algorithm Hash digest
SHA256 bb35937bea951517ade6a277e21269087277fe70d22449d7fac438ed1dd450aa
MD5 ffa6646bc04b08898b4a67a1bd983157
BLAKE2b-256 6e14006d2b295f7778d763baeadbfc42cdb885fbb9ec1b68235c5ce842f0a8c7

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

This release

0.1.5003 This release

2 files

0.1.5001

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.4

2 files

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page