Principle:1Panel dev MaxKB Async Embedding
| Knowledge Sources | |
|---|---|
| Domains | RAG, Async_Tasks |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
A concurrency pattern that offloads embedding generation to background task queues, preventing HTTP request blocking during document vectorization.
Description
Generating embeddings for document paragraphs is computationally expensive and can take seconds to minutes for large documents. Async embedding moves this work to a Celery worker process, allowing the HTTP upload request to return immediately while embedding happens in the background. The pattern uses celery-once (QueueOnce) to prevent duplicate embedding tasks for the same document, which is critical when multiple triggers (upload, re-embed, model change) might fire concurrently. The task delegates to ListenerManagement which iterates paragraphs, calls the embedding model, and persists vectors via PGVector.
Usage
Use this principle when designing:
- Document ingestion pipelines with non-blocking uploads
- Background embedding generation for large documents
- Idempotent task execution with deduplication
Theoretical Basis
The async embedding pattern follows the Command Pattern with Idempotency guarantees:
# Abstract algorithm description (NOT real implementation)
@task(deduplicate_by="document_id")
def embedding_by_document(document_id, model_id):
paragraphs = load_paragraphs(document_id)
embedding_model = get_embedding_model(model_id)
vectors = embedding_model.embed_documents([p.text for p in paragraphs])
vector_store.batch_save(paragraphs, vectors)
update_document_status(document_id, "SUCCESS")
The QueueOnce base class ensures that only one task per `document_id` is active at a time, preventing race conditions and resource waste.