The rag-mongo template bootstraps a Python LangChain application for retrieval-augmented generation backed by MongoDB Atlas and Atlas Vector Search. section 14.5 section 14.5.1
Create and expose the application with these steps:
- Run `langchain app new mongodb-in-action --package rag-mongo`, optionally adding `--non-interactive` to suppress prompts. section 14.5.1
- Install `langchain_openai`, then inspect the generated `app`, `packages/rag-mongo`, `ingest.py`, and `rag_mongo/chain.py` files. section 14.5.1
- Import the chain into `server.py` and expose it at `/rag-mongo` with LangServe. section 14.5.1
- Run `langchain serve` and open `/rag-mongo/playground/` on local port 8000 to test the chatbot. section 14.5.4
The generated package separates ingestion from answering: `ingest.py` loads data into MongoDB and interacts with Atlas Vector Search, while `chain.py` combines retrieved context with a language model. section 14.5.1
Trace a question through the chain
For “What indexes does MongoDB support?”, RunnableParallel prepares the question and context, the Retriever finds relevant Atlas Vector Search documents, RunnablePassthrough forwards context, ChatPromptTemplate structures the prompt, ChatOpenAI generates an answer, and StrOutputParser returns the text. section 14.6 section 14.5.4
Listing 14.1 Files and directories in the LangChain project
├── Dockerfile ├── README.md ├── app │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-312.pyc │ │ └── server.cpython-312.pyc │ └── server.py ├── packages │ ├── README.md │ └── rag-mongo │ ├── LICENSE │ ├── README.md │ ├── _images │ │ ├── cluster.png │ │ ├── collections.png │ │ ├── connect.png │ │ ├── create.png │ │ ├── driver.png │ │ ├── json.png │ │ ├── json_editor.png │ │ ├── search-indexes.png │ │ └── uri.png │ ├── ingest.py │ ├── pyproject.toml │ ├── rag_mongo │ │ ├── __init__.py │ │ └── chain.py │ ├── rag_mongo.ipynb │ └── tests │ └── __init__.py └── pyproject.toml
Inspect the generated project layout to locate the server, ingestion script, package metadata, chain implementation, notebook, and tests. section 14.5.1
