A Django application that ingests Federal Register regulatory documents (e.g., EPA rules), auto-embeds them, and enables semantic Q&A search over them using MongoDB Atlas Vector Search.
Documents are stored as plain text, MongoDB Atlas automatically generates and manages the embeddings for the abstract field via Atlas vector search index's built-in embedding model, so there's no separate embedding service or API call to maintain.
- Python 3.13+
- A MongoDB Atlas cluster with an
auto-embedding (automated embedding) vector search index
configured on the
abstractfield of thedocuments_documentcollection.
-
Clone the repo and create a virtual environment:
python -m venv .venv source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile in the project root with the following variables:SECRET_KEY=your-django-secret-key MONGODB_URI="mongodb+srv://<username>:<password>@<cluster>.mongodb.net/?appName=documents" DB_NAME=your-database-name VECTOR_INDEX_NAME=your-vector-index-name -
Apply migrations:
python manage.py migrate
Fetch regulatory documents from the Federal Register API and save them to MongoDB:
python manage.py ingest_federal_register --agency environmental-protection-agency --limit 100--agency: Federal Register agency slug (default:environmental-protection-agency)--limit: maximum number of documents to save
No embedding step is required here because once documents land in the collection, MongoDB Atlas's vector search index auto-embeds the abstract field in the background.
Run a plain-text semantic search over the ingested documents:
python manage.py search_docs "What are the emissions standards for diesel engines?"The question text is passed directly to $vectorSearch — MongoDB auto-embeds the query using the index, so no query vector or external embedding call is needed. Results are ranked by vector search score and show the document number and title.
- documents/models.py — the
Documentmodel - documents/services/search_service.py — MongoDB vector search query logic
- documents/management/commands/ —
ingest_federal_registerandsearch_docscommands - regulations_qa/ — Django project settings and configuration
- mongo_migrations/ — Mongo-backed migrations for Django's built-in apps
NB: The Data used comes from the Federal Register, which publishes US government documents. This project is independent and not affiliated with or endorsed by the Federal Register.