Installable RAG infrastructure for Django projects.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_agent_rag-0.1.0.tar.gz.
File metadata
- Download URL: django_agent_rag-0.1.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6b21b1dc5170e04e72d89f230a5e958bf396e1628946e289405c0cedeeb9d00
|
|
| MD5 |
9c0611a58f135c2f33affbfc286a3c67
|
|
| BLAKE2b-256 |
5475994ed542ffbad8f2a28dabe844eebb5a9945054a1685f689dee9f01a8efd
|
Provenance
The following attestation bundles were made for django_agent_rag-0.1.0.tar.gz:
Publisher:
python-publish.yml on Akamad007/django-agent-rag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_agent_rag-0.1.0.tar.gz -
Subject digest:
e6b21b1dc5170e04e72d89f230a5e958bf396e1628946e289405c0cedeeb9d00 - Sigstore transparency entry: 1109293189
- Sigstore integration time:
-
Permalink:
Akamad007/django-agent-rag@db366a17460887bf80cab5abba5b4b2d0c683925 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Akamad007
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@db366a17460887bf80cab5abba5b4b2d0c683925 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file django_agent_rag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_agent_rag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76e5791e4e49e1e3175af674f00baa4f0bf8fd348758a38b4f95ca651ffae1e4
|
|
| MD5 |
f8550150c7a00bae112b4861e8750f8c
|
|
| BLAKE2b-256 |
7fb0714915b5e7548a70712575cfd6eccb917291fb981993d5fbdf910abbea06
|
Provenance
The following attestation bundles were made for django_agent_rag-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on Akamad007/django-agent-rag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_agent_rag-0.1.0-py3-none-any.whl -
Subject digest:
76e5791e4e49e1e3175af674f00baa4f0bf8fd348758a38b4f95ca651ffae1e4 - Sigstore transparency entry: 1109293193
- Sigstore integration time:
-
Permalink:
Akamad007/django-agent-rag@db366a17460887bf80cab5abba5b4b2d0c683925 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Akamad007
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@db366a17460887bf80cab5abba5b4b2d0c683925 -
Trigger Event:
workflow_dispatch
-
Statement type: