django-agent-rag
Installable RAG infrastructure for Django projects.
django-agent-rag is a reusable Django app that adds document ingestion, chunking, embeddings, pgvector-backed retrieval, context assembly, pluggable LLM backends, pluggable embedding backends, and optional async execution backends.
It is:
- Django-first
- provider-agnostic
- PostgreSQL + pgvector focused
- sync by default
- optionally integrated with Celery and Temporal
It is not:
- a full UI product
- a full authentication package
- tied to a single model vendor
- a giant agent framework
Features
- Install with
pip install django-agent-rag - Add to
INSTALLED_APPS - Manage source documents, chunks, conversations, retrieval runs, and agent runs
- Use pgvector as the v1 vector store
- Swap LLM and embedding providers through import-string based settings
- Run ingestion synchronously or through Celery or Temporal adapters
- Use management commands and Django admin for operations
- Develop locally with built-in fake providers
Installation
pip install django-agent-rag
From this repository during development:
pip install -e .
If you use pyenv, this repository includes .python-version set to django-agent-rag, so entering the project directory can select that environment automatically when pyenv is configured in your shell.
Optional extras:
pip install "django-agent-rag[celery]"
pip install "django-agent-rag[temporal]"
pip install "django-agent-rag[dev]"
Developer setup from source:
pip install -r requirements-dev.txt
Add the app:
INSTALLED_APPS = [
# ...
"pgvector.django",
"django_agent_rag",
]
Configure DJANGO_AGENT_RAG:
DJANGO_AGENT_RAG = {
"VECTOR_STORE_CLASS": "django_agent_rag.retrievers.pgvector.PGVectorRetriever",
"EMBEDDING_BACKEND": "django_agent_rag.backends.embeddings.fake.FakeEmbeddingBackend",
"LLM_BACKEND": "django_agent_rag.backends.llm.fake.FakeLLMBackend",
"TASK_BACKEND": "django_agent_rag.backends.tasks.sync.SyncTaskBackend",
"CHUNKER_CLASS": "django_agent_rag.chunkers.simple.SimpleChunker",
"DEFAULT_CHUNK_SIZE": 500,
"DEFAULT_CHUNK_OVERLAP": 50,
"DEFAULT_TOP_K": 5,
"AUTO_CREATE_EXTENSION": True,
"DEFAULT_DISTANCE_STRATEGY": "cosine",
"ENABLE_ADMIN": True,
"ENABLE_MANAGEMENT_COMMANDS": True,
}
Run migrations:
python manage.py migrate
PostgreSQL and pgvector
v1 supports PostgreSQL only. The package ships a migration that creates the vector extension with CREATE EXTENSION IF NOT EXISTS vector;.
Local development stack:
docker compose up -d postgres redis
Basic usage
from django_agent_rag import ask, index_text, retrieve
document = index_text(
text="Django apps can be packaged and reused.",
title="Reusable apps",
external_id="doc-1",
metadata={"topic": "django"},
)
results = retrieve("How does Django support reuse?", top_k=3)
response = ask("How does Django support reuse?", top_k=3)
Sync usage
Sync is the default backend. Service functions call chunking and embedding inline:
from django_agent_rag.services import ingest_text
document = ingest_text(text="hello world", title="Greeting")
Celery usage
Install the extra:
pip install "django-agent-rag[celery]"
Switch the task backend:
DJANGO_AGENT_RAG = {
# ...
"TASK_BACKEND": "django_agent_rag.backends.tasks.celery_backend.CeleryTaskBackend",
}
Then wire Celery in your project and import django_agent_rag.celery_tasks.
Temporal usage
Install the extra:
pip install "django-agent-rag[temporal]"
Switch the task backend:
DJANGO_AGENT_RAG = {
# ...
"TASK_BACKEND": "django_agent_rag.backends.tasks.temporal_backend.TemporalTaskBackend",
}
Temporal remains optional. It requires a Temporal service, workers, and task queue configuration. The package isolates Temporal imports so base installs still work.
Custom embedding backend
from django_agent_rag.backends.embeddings.base import EmbeddingBackend
class MyEmbeddingBackend(EmbeddingBackend):
def embed_text(self, text: str) -> list[float]:
return self.embed_texts([text])[0]
def embed_texts(self, texts: list[str]) -> list[list[float]]:
return [[0.0, 1.0, 0.0] for _ in texts]
def dimensions(self) -> int:
return 3
def provider_name(self) -> str:
return "my-embeddings"
Custom LLM backend
from django_agent_rag.backends.llm.base import LLMBackend
from django_agent_rag.types import LLMResponse
class MyLLMBackend(LLMBackend):
def generate(self, prompt: str, system_prompt: str | None = None, context: list[str] | None = None, **kwargs) -> LLMResponse:
return LLMResponse(
text=f"Prompt: {prompt}",
provider=self.provider_name(),
raw={"context": context or []},
)
def provider_name(self) -> str:
return "my-llm"
Running tests
make test
The test suite expects PostgreSQL for vector integration tests. Temporal tests skip gracefully when the dependency or service is unavailable.
Linting and packaging
make lint
make format
make check-dist
make check-dist builds the sdist and wheel, then runs twine check to validate the package metadata before publishing.
Local development
make install-dev
docker compose up -d
make migrate
make test
See examples/demo_project for a minimal Django project wired to the package.
Publishing to PyPI
This repository publishes with PyPI Trusted Publishing using GitHub Actions OIDC. The publish workflow is:
.github/workflows/python-publish.yml
Publishing is triggered when a GitHub Release is published, and it can also be run manually with workflow_dispatch.
Only the publish job gets id-token: write. The build job keeps minimal permissions.
Before publishing, PyPI must be configured with a trusted publisher that exactly matches:
- GitHub owner:
akamad007 - repository name:
django-agent-rag - workflow filename:
.github/workflows/python-publish.yml - environment name:
pypi
If any of those do not match, PyPI will reject the publish request.
Maintainer flow:
- Update the version in
pyproject.toml. - Run
make check-dist. - Push the version change.
- Create a GitHub Release to trigger publishing.
Maintainer notes:
- The workflow file path must exactly match what is configured on PyPI.
- Reusable GitHub workflows cannot currently be used as the trusted workflow for PyPI Trusted Publishing.
- Environment mismatches can cause publish failures.
- Stale package references should point to
django-agent-rag, including the PyPI project URL:https://pypi.org/project/django-agent-rag/.
See PUBLISHING.md for the short maintainer checklist.
Metadata
Release files for django-agent-rag 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_agent_rag-0.1.0.tar.gz | 22.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_agent_rag-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.9 kB
Release files / django_agent_rag-0.1.0.tar.gz
| Download URL | django_agent_rag-0.1.0.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6b21b1dc5170e04e72d89f230a5e958bf396e1628946e289405c0cedeeb9d00
|
|
BLAKE2b-256 checksum How to use checksums |
5475994ed542ffbad8f2a28dabe844eebb5a9945054a1685f689dee9f01a8efd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 16, 2026.
Transparency logRelease files / django_agent_rag-0.1.0-py3-none-any.whl
| Download URL | django_agent_rag-0.1.0-py3-none-any.whl |
|---|---|
| Size | 30.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76e5791e4e49e1e3175af674f00baa4f0bf8fd348758a38b4f95ca651ffae1e4
|
|
BLAKE2b-256 checksum How to use checksums |
7fb0714915b5e7548a70712575cfd6eccb917291fb981993d5fbdf910abbea06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 16, 2026.
Transparency logSecurity for django-agent-rag 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_agent_rag-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.