AI Conversational Retrieval

A workflow based on LangChain's conversational retrieval agents that I used in the AI bible research project to upload documents and ask them questions.

Cover image for AI Conversational Retrieval

Python Notebook Setup

In this guide, you'll see how to process text files into a vector database using embeddings.

Then you can ask questions and the chat agent will respond with relevant pieces of your docs as context.

This notebook serves as a prompt template testing kit.

Once you find a prompt you like, you can turn this into a looping script you can run in a terminal. Like this example.

Prerequisites

  1. LangChain and requisites installed. See LangChain installation docs
  2. A folder named data with the .txt files you want to query or a single file, named data.txt.
  3. An API key from OpenAI
  4. A file named constants.py to store the API key

Then import the required libraries and the API key.

Next, create the vector store.

Persist = True creates, if it doesn't exist, and reuses a vector store.

Persist = False creates a new vector store each time.

Now, we'll tell it which model to use.

And run the chain.

The result...