Coder Social home page Coder Social logo

ashishd / rag-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from renumics/renumics-rag

0.0 0.0 0.0 1.29 MB

Retrieval-Augmented Generation Assistant Demo 🤖➕📚🟰❤️

License: MIT License

Python 54.58% Makefile 1.68% Jupyter Notebook 43.74%

rag-demo's Introduction

🤖 RAG Demo

Retrieval-augmented generation assistant demo using LangChain and Streamlit.

🛠️ Installation

Setup a virtual environment in the project directory:

python3.8 -m venv .venv
source .venv/bin/activate  # Linux/MacOS
# .\.venv\Scripts\activate.bat  # Windows CMD
# .\.venv\Scripts\activate.ps1  # PowerShell
pip install -IU pip setuptools wheel

Install the RAG demo package and some extra dependencies:

# For GPU support
pip install git+https://github.com/Renumics/rag-demo.git[all] pandas renumics-spotlight torch torchvision sentence-transformers accelerate
# For CPU support
# pip install git+https://github.com/Renumics/rag-demo.git[all] pandas renumics-spotlight torch torchvision sentence-transformers accelerate --extra-index-url https://download.pytorch.org/whl/cpu

⚒️ Local Setup

If you intend to edit, not simply use, this project, clone the entire repository:

git clone [email protected]:Renumics/rag-demo.git

Then install it in editable mode.

Via pip

Setup virtual environment in the project folder:

python3.8 -m venv .venv
source .venv/bin/activate  # Linux/MacOS
# .\.venv\Scripts\activate.bat  # Windows CMD
# .\.venv\Scripts\activate.ps1  # PowerShell
pip install -IU pip setuptools wheel

Install the RAG demo package and some extra dependencies:

pip install -e .[all]
# For GPU support
pip install pandas renumics-spotlight torch torchvision sentence-transformers accelerate
# For CPU support
# pip install pandas renumics-spotlight torch torchvision sentence-transformers accelerate --extra-index-url https://download.pytorch.org/whl/cpu

Via poetry

Install the RAG demo and some extra dependencies:

poetry install --all-extras
# Torch with GPU support
pip install pandas renumics-spotlight torch torchvision sentence-transformers accelerate
# Torch with CPU support
# pip install pandas renumics-spotlight torch torchvision sentence-transformers accelerate --extra-index-url https://download.pytorch.org/whl/cpu

Activate the environment (otherwise, prexis all subsequent commands with poetry run):

poetry shell

Note: If you have Direnv installed, you can avoid prefixing python commands with poetry run by executing direnv allow in the project directory. It will activate environment each time you enter the project directory.

⚙️Configuration

If you plan to use OpenAI models, create .env with the following content:

OPENAI_API_KEY="Your OpenAI API key"

If you plan to use OpenAI models via Azure, create .env with the following content:

OPENAI_API_TYPE="azure"
OPENAI_API_VERSION="2023-08-01-preview"
AZURE_OPENAI_API_KEY="Your Azure OpenAI API key"
AZURE_OPENAI_ENDPOINT="Your Azure OpenAI endpoint"

If you are using Hugging Face models, a .env file is not necessary.

Modify parameters if desired in the settings file.

Note: you can create different settings files and toggle between them by setting the RAG_SETTINGS environment variable.

🚀 Usage

Create a new data/docs directory within the project and place your documents in there (recursive directories are supported).

Note: at the moment, only HTML files can be indexed but it can be adjusted in the create-db script.

Begin the process by indexing your documents. Execute the following command:

create-db

This will create a db-docs directory within the project consisting of indexed documents. To index additional documents, use the --exist-ok and --on-match flags (refer to create-db --help for more information).

Now, you can leverage the indexed documents to answer questions.

To only retrieve relevant documents:

retrieve "Your question here"
# QUESTION: ...
# SOURCES: ...

To answer a question based on the indexed documents:

answer "Your question here"
# QUESTION: ...
# ANSWER: ...
# SOURCES: ...

To start a web application:

app

See app --help for available application options.

After submitting some questions, you can explore them using Renumics Spotlight:

explore

rag-demo's People

Contributors

druzsan avatar markus-stoll avatar renumics 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.