Skip to content

A simple Python RAG implementation with MongoDB Vector Search, LangChain and OpenAI

Notifications You must be signed in to change notification settings

Natural0rder/rag-mongodb-langchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Prerequisites

Run the following commands to create your app based on rag-mongo template:

pip install langchain-cli
pip install openai
langchain app new <my-app-name> --package rag-mongo
export OPENAI_API_KEY=<my-openai-api-key>
export MONGO_URI=<my-mongodb-cs>

Update app/server.py

Add the route to your app:

from rag_mongo import chain as rag_mongo_chain
add_routes(app, rag_mongo_chain, path="/rag-mongo")

Update rag-mongo/ingest.py parameters

image
DB_NAME = "database-name"
COLLECTION_NAME = "collection-name"
ATLAS_VECTOR_SEARCH_INDEX_NAME = "vector-index-name"
EMBEDDING_FIELD_NAME = "embedding"
# PDF file to split location
FILE_URI = "https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RE4HkJP" 
CHUNK_SIZE = 500
CHUNK_OVERLAP = 0

Udpate rag-mongo/chain.py paramaters

image
DB_NAME = "database-name"
COLLECTION_NAME = "collection-name"
ATLAS_VECTOR_SEARCH_INDEX_NAME = "vector-index-name"
SEARCH_K_VALUE = 100
POST_FILTER_PIPELINE_LIMIT = 1
OPENAI_MODEL_NAME = "gpt-3.5-turbo-16k-0613"

Run ingest.py to create documents

python3 ingest.py

Create the Atlas Vector Search index

{
  "fields": [{
    "path": "embedding",
    "numDimensions": 1536,
    "similarity": "cosine",
    "type": "vector"
  }]
}

Serve the app

Run LangServe at /app level

langchain serve
image

Browse the app

http://localhost:8000/rag-mongo/playground/
image

About

A simple Python RAG implementation with MongoDB Vector Search, LangChain and OpenAI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages