Skip to content

vinibgoulart/gitbook-rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitbook-rag

This project is a proof of concept to show how to use the pgvector extension to make queries in a database using the cosine similarity.

Brief explanation

The project have a sync service that makes a request to the gitbook api every 1 hour to get the data from the pages and save it in the database. The data is saved in the table page and the vector representation of the data is saved in the table page.embedding.

When you run the api or cli, you can make queries to the database using the cosine similarity to get the most similar pages to a given prompt.

image image

Pre-requisites

  • create the database in postgresql
  • run the postgresql
  • fill the environment variables in the .env file
  • have the pgvector extension installed

How to install the pgvector extension

git clone https://github.com/pgvector/pgvector.git
cd pgvector
make
sudo make install

Installation

go mod tidy

Running with docker

docker-compose up -d

This command will start the postgresql and the pgadmin services.

Running the worker

To sync the data from the database to the vector index you need to run the worker with the following command:

make worker

With this, a request will be made to the gitbook every 1 hour to sync the data.

Running the cli

To consume the database make queries to the vector index you need to run the cli with the following command:

make cli

Running the api

To consume the database make queries to the vector index you need to run the api with the following command:

make api

API Endpoints

Method Endpoint Description Parameters
POST /ai/page Send a prompt to the chat bot { "prompt": "string" }
GET /chat Get the current session and chat messages null
POST /logout Logout from the current session scope null

About

Vectorizing your gitbook in postgres database

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published