Coder Social home page Coder Social logo

faiss-qa-test's Introduction

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.

faiss-qa-test's People

Contributors

gingeard avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.