.env
: Contains environment variables, such as API keys..env.example
: Example of the.env
file..python-version
: Specifies the Python version used in the project.memory.ipynb
: Jupyter Notebook containing the main code for the project.requirements.txt
: Lists the dependencies required for the project.
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Set up environment variables:
-
Copy
.env.example
to.env
:cp .env.example .env
-
Fill in the required values in the
.env
file.
-
-
Run the Jupyter Notebook:
jupyter notebook memory.ipynb
-
Execute the cells in
memory.ipynb
to see the Conversational RAG Chain in action.
-
Session History Retrieval:
messages = conversational_rag_chain.get_session_history("abc123").messages
-
Message Formatting:
for i, message in enumerate(messages): if isinstance(message, HumanMessage): print(f"Human: {message.content}") elif isinstance(message, AIMessage): print(f"AI: {message.content}") print() # Adds a blank line between each pair of messages
-
Chain Creation:
history_aware_retriever = create_history_aware_retriever(llm, retriever, contextualize_q_prompt) question_answer_chain = create_stuff_documents_chain(llm, qa_prompt) rag_chain = create_retrieval_chain(history_aware_retriever, question_answer_chain)
-
Invoke Chain:
conversational_rag_chain.invoke( {"input": "Where the people surf in the beginnings?"}, config={ "configurable": {"session_id": "abc123"} }, )["answer"]
langchain
langchain-community
langchainhub
langchain-chroma
beautifulsoup4
python-dotenv
langchain-openai
This project is licensed under the MIT License.