Skip to content

Uses Milvus and OpenAI's API to perform question answering over documents with a chat interface

Notifications You must be signed in to change notification settings

Snaiel/OpenAI-Milvus-QA-Over-Docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI-Milvus-QA-Over-Docs

screenshot of program

Uses Milvus as a document store and OpenAI's chat API for a simple app that allows the user ask question based on given sources. Stores every question asked and answer generated in an SQLite relational database which provides additional functionality and analysis.

  • Supports CSV, PDF files
  • Supports web pages
  • Shows sources in response
  • Aims to provide as much context to the AI model
  • Stores all questions and answers
  • No chat memory/history

How it works

diagram of architecture

  1. A Milvus and SQLite instance is run
  2. Files and websites are ingested through Langchain's document loaders and text splitter
  3. Documents embedded by OpenAI embeddings and added to Milvus collection through langchain. References of these documents are put in an SQLite table.
  4. Only data ingestion done through Langchain, rest uses pymilvus and openai
  5. A user inputs a query into the chat interface, and gets embedded by OpenAI embeddings (okay embeddings still done through langchain)
  6. Similarity search is done with the embedded query on previous questions
  7. Using distance, it deems whether the question is similar or identical to a previous question.
  8. If so, retrieve the previous response
  9. If there are no relevant questions or users specifies to generate a new answer, do a similarity search on the sources and retrieve the top 20 most similar documents
  10. From the top 20, as much context/text is retrieved until the token limit is reached. 4096 for OpenAI gpt-3.5 (maximum set to 3700 to leave room for response tokens)
  11. Instructions, the context, and the original question is given to the OpenAI chat model
  12. Response is returned and displayed in a chat interface

How to run

Install and run a Milvus instance

Make sure you have the necessary requirements to run the Python program

pip install -r requirements.txt

Create a .env file in the directory and put the OpenAI API key in as follows:

OPENAI_API_KEY=...

Then run the app with

flask run or python3 app.py

A Flask app will run locally. Click on the url provided in the terminal to open the app. For example:

http://127.0.0.1:5000

About

Uses Milvus and OpenAI's API to perform question answering over documents with a chat interface

Topics

Resources

Stars

Watchers

Forks