Skip to content

gingeard/faiss-qa-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FAISS QA

This is a simple example of using the FAISS (Facebook AI Similarity Search), LangChain framework and OpenAI API to find the most similar answer to the question from the predefined list of documents (for example, from FAQ database, Support system and so on).

The script accomplishes the following general steps:

  1. Initializes a FAISS vector store with a list of documents by:
    • transforming the list of documents into a vectorized DataFrame,
    • utilizing the OpenAI API for initializing embeddings,
    • creating a vector store from these vectorized documents and embeddings.
  2. Performs a similarity search by:
    • using user input to execute a similarity search with FAISS,
    • ranking the documents based on similarity,
    • selecting the most relevant document.
  3. Generates a response by:
    • setting up a Language Model chain using the LangChain.
    • adds the user input to the most relevant document (for generating a contextually relevant response)
    • using the OpenAI API to generate a response based on the prompt.

Install requirements

python -m venv faiss-qa-venv
source faiss-qa-venv/bin/activate
pip install -r requirements.txt

Before run add .env file with the OpenAI API key

OPEN_AI_KEY = "sk-xxxxxxxx"

You can obtain the API key from the OpenAI API keys page.

Running example

$ python faiss-qa.py   # input = "I forgot my password."

If you forgot your password, you can reset it by clicking on the 'Forgot Password?' link
on the login page. Enter your email address, and we will send you instructions on how to reset
your password. For more information, please refer to this link: https://example.com/confluence/recover-password.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages