Created a RAG using 3 free options:
- Mistral (full online)
- HuggingFace (LLM online, embeddings local)
- Ollama (local) It uses a python backend with an html/js/css frontend to interact with it.
You will need Docker for all versions. If you don't have it, you can download it here.
Open the compose folder inside the docker folder and follow the instructions
- You need python installed. We recommend creating a venv for the app, so it doesn't have problems with interdependencies with other python you might have.
- Make sure you have all the requirements needed.
Download it manually or using the terminal:
git clone https://github.com/MiguelGP-13/Projects-RAG.gitImportant
The env file must be in the RAG folder, not elsewhere
DB_PASSWORD=<DB_PASSWORD IN .env>
API_MISTRAL=<Mistral API>
API_HUGGINGFACE=<HuggingFace API>Note
The only api key needed is the one you are going to use To get a Mistral API:
- Create an account or login if you alredy have one at Mistral.
- Go to the api key section and click on
Create a new Key. - Copy the key and put it in the .env file.
Make sure it has this information if you choose Mistral or HuggingFace as MODE.
MODE=Mistral
CHUNK_SIZE=512
CONTEXT_SIZE=3
DOCUMENT_FOLDER=Backend/documents
QUESTIONNAIRES_FOLDER=Backend/questionnaires
CHATS_FOLDER=Backend/chatsIf you want to use local LLM:
MODE=Local
MODEL=<Model you want to use (for example: mistral)>
EMBEDDINGS=<Model you want to use (for example: jina/jina-embeddings-v2-base-en)>
DIMENSION=<Dimension of embeddings generated (768 for jina embeddings)>
CHUNK_SIZE=512
CONTEXT_SIZE=3
DOCUMENT_FOLDER=Backend/documents
QUESTIONNAIRES_FOLDER=Backend/questionnaires
CHATS_FOLDER=Backend/chatsImportant
Create the folders you are indicating in settings.env (documents, questionnaires and chats)
docker run -d --name redis-stack -p 6379:6379 -p 8361:8001 -e REDIS_ARGS="--requirepass <DB_PASSWORD IN .env>" redis/redis-stack:latestTip
If the command is not working, make sure Docker is alredy running
Start the docker engine and the redis db
docker desktop start
docker start redis-stackStart the backend API
cd Backend
python main.pyOpen the web so you can use the app Linux:
cd ../Frontend
xdg-open file.htmWindows:
cd ../Frontend
start file.htmNote
You can also open it clicking on the file
main.html: Chat where you ask questions about the documents uploaded.
files.html: Page to upload files for the RAG to use.
{"success": false, "error_code": "Code (int)", "description": "Error description"}Payload:
{"prompt": "QUERY", "chat": "Chat selected"}Answer:
Chat:
{"success": true, "answer": "LLM answer"}RAG:
{"success": true, "answer": "LLM answer", "references": "Id of context peices", "reference_text": "Context pieces text"}Payload:
{"file_name": "filename", "clear_database": true}Answer:
{
"success": true,
"description": "The file filename was deleted",
"database_cleared": "n_chunks chunks deleted"
}Payload:
{"pdfs_array": ["PDF NAME 1", "PDF NAME 2", "..."]}Answer:
{
"success": true,
"pdfs_created": ["PDF NAME 1", "PDF NAME 2", "..."],
"number_of_chunks": "n_chunks new chunks were created"
}Payload:
files[]: Array of .pdf files
Answer:
{
"success": true,
"pdfs_created": ["PDF NAME 1", "PDF NAME 2", "..."],
"number_of_chunks": "n_chunks new chunks were created"
}Answer:
{"success": true, "files": ["PDF NAME 1", "PDF NAME 2", "..."]}Answer:
{
"success": true,
"chats": [
{
"realName": "My Chat",
"id": "hash",
"creationDate": "timestamp"
},
...
]
}Answer:
{
"success": true,
"chat": [ "Conversation saved" ]
}Answer:
{"success": true, "id": "hash"}Answer:
{"success": true, "deleted": "id.json"}Payload:
{"pdfs_array":["PDF NAME 1", "PDF NAME 2", "..."],
"level":2, // From 1 to 4
"number_of_questions":5}Answer:
{"success": true, "questionnaireId": 1234}Answer:
{"success": true, "deleted": "id.json"}Answer:
{"success": true,
"questions": [{"question":"",
"options": ["..."],
"correctOption":1}]
}Answer:
{"success": true,
"questions": [{"question":"",
"options": ["..."],
"correctOption":1}]
}Answer:
{"success": true, "newName": "newName", "oldName":"oldName"}Answer: Serves main.html from frontend
Answer:
{"success": true}
{"success": false, "description":"What's not up running"}| Code | Description |
|---|---|
| 0 | Unexpected error |
| 100 | A compulsory value wasn't found in the JSON provided with the POST |
| 101 | File trying to add already exists |
| 102 | The path of the file provided doesn't exist |
| 103 | Error occurred while fetching files |
| 104 | No files arrived to the backend |
| 105 | The file you are trying to find does not exist |
| 106 | Conversation with that name already exists |
| 107 | Conversation name can't have dots (".") |
| 108 | Conversation name can't start with a number |
| 109 | Conversation name can't be empty |
| 110 | Incorrect query mode |
| 111 | The questionnaire you are trying to find does not exist |