Git Product home page Git Product logo

retrieval-backend-with-rag's Introduction

Vietnamese Retrieval Backend: RAG + MongoDB + Gemini 1.5 Pro

This demo will be presented at Google I/O Extended HCMC 2024.

Slide

Set up

1. Installation

This code requires Python >= 3.9.

pip install -r requirements.txt

2. Environment Variables

Create a file named .env and add the following lines, replacing placeholders with your actual values:

MONGODB_URI=
EMBEDDING_MODEL=
DB_NAME=
DB_COLLECTION=
GEMINI_KEY=
  • MONGODB_URI: URI of your MongoDB Atlas instance.
  • EMBEDDING_MODEL: Name of the embedding model you're using for text embedding.
  • DB_NAME: Name of the database in your MongoDB Atlas.
  • DB_COLLECTION: Name of the collection within the database.
  • GEMINI_KEY: Your key to access the Gemini API.

3. Data

Prepare your data following the format below:

For this project, we are using MongoDB Atlas for Vector Search.

Make sure you create a Vector Search Index. Follow this video.

4. Edit your Prompt in serve.py

In the serve.py file, you can see that we used the prompt like this. This prompt was enhanced by adding information about your products to it.

f"Hãy trở thành chuyên gia tư vấn bán hàng cho một cửa hàng điện thoại. Câu hỏi của khách hàng: {query}\nTrả lời câu hỏi dựa vào các thông tin sản phẩm dưới đây: {source_information}."
  • query: Query from the user.
  • source_information: Information we get from our database.

The full prompt will look like this:

Hãy trở thành chuyên gia tư vấn bán hàng cho một cửa hàng điện thoại. Câu hỏi của khách hàng: Samsung Galaxy Z Fold4 512GB
Trả lời câu hỏi dựa vào các thông tin sản phẩm dưới đây: 
 1) Tên: điện thoại samsung galaxy z fold5 12gb/512gb - chính hãng, Giá: 30,990,000 ₫, Ưu đãi: - KM 1
- Tặng gói Samsung care+ 6 tháng
- KM 2
- Trả góp tới 06 tháng không lãi suất, trả trước 0 đồng với Samsung Finance+.

 2) Tên: điện thoại ai - samsung galaxy s24 - 8gb/512gb - chính hãng, Giá: 25,490,000 ₫, Ưu đãi: - KM 1
- Trả góp tới 06 tháng không lãi suất, trả trước 0 đồng với Samsung Finance+.
- KM 2
- Giảm thêm 1.000.000đ cho khách hàng thân thiết (Chi tiết LH 1900 ****)

 3) Tên: điện thoại samsung galaxy s23 ultra 12gb/512gb - chính hãng, Giá: 26,490,000 ₫, Ưu đãi: - KM 1
- Trả góp tới 06 tháng không lãi suất, trả trước 0 đồng với Samsung Finance+.

The prompt is then fed to LLMs.

5. Run server

python serve.py

6. Testing API

Testing on web-app. Link

retrieval-backend-with-rag's People

Contributors

bangoc123 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.