Skip to content

Commit 85f4f31

Browse files
authored
Merge pull request #7 from WillACosta/feature/improve-ai-flow
[AUTOMATED-PR] - main <- feature/improve-ai-flow
2 parents b4c606e + d0300c0 commit 85f4f31

File tree

41 files changed

+598
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+598
-179
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.env-example

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
PORT=3000
2-
IS_DOCKER=false
32

43
LANGCHAIN_API_KEY=
54
LANGCHAIN_TRACING_V2=true
65
LANGCHAIN_CALLBACKS_BACKGROUND=true
76

87
LLM_API_KEY=
98

10-
REDIS_URL=redis://127.0.0.1:6379
11-
REDIS_URL_DOCKER=redis://redis:6379
9+
REDIS_URL=redis://redis:6379
1210
REDIS_USER=
1311
REDIS_PASSWORD=
1412

15-
DATABASE_URL=postgresql://genaiapp:password@localhost:5432/app_db?schema=public
16-
DATABASE_URL_DOCKER=postgresql://genaiapp:password@postgres:5432/app_db?schema=public
13+
DATABASE_URL=postgresql://genaiapp:<password>@postgres:5432/app_db?schema=public
1714

1815
JWT_SECRET=
1916
JWT_EXPIRATION=1h
17+
18+
QDRANT_URL=http://qdrant:6333
19+
QDRANT_COLLECTION=genai_documents

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
## Changes made in this PR
1+
### Description
2+
3+
<!-- Add a full description of the changes here -->

.vscode/settings.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"cSpell.words": [
3-
"dataprovider",
4-
"dataproviders",
5-
"gemini",
6-
"nodenext",
7-
"openapi",
8-
"predev",
9-
"prestart",
10-
"usecases"
11-
]
3+
"dataprovider",
4+
"dataproviders",
5+
"gemini",
6+
"nodenext",
7+
"openapi",
8+
"predev",
9+
"prestart",
10+
"qdrant",
11+
"usecases"
12+
]
1213
}

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
help:
2+
@echo "Available commands:"
3+
@echo " run Start app and services using Docker."
4+
@echo " stop-all Stop all services running on Docker."
5+
@echo " remove Remove all Docker containers."
6+
@echo " clean Remove temporary and cache files."
7+
8+
run:
9+
docker compose up -d
10+
11+
build:
12+
docker compose up --build -d
13+
14+
stop-all:
15+
docker compose stop $(docker ps -q)
16+
17+
remove:
18+
docker compose down
19+
20+
clean:
21+
rm -rf node_modules/ uploads/*.pdf

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ modules: application features
4141
utils: class and constant utilities for this module
4242
```
4343
44-
### Search In Document Flow
44+
### Search In Documents Flow
4545
46-
The search in document endpoint is the most complex of this application, it uses RAG concepts to break down the provided
47-
PDF document into small chunks and use it as context to the follow-up questions. Also, it uses Redis to store
48-
and retrieve chat history during user's session.
46+
To perform a search in documents and ask questions about them, we have two endpoints for that:
4947
50-
> A possible improvement, is to have a separated endpoint for uploading documents and another one for handling questions
51-
> to it. For this initial version the endpoint accepts one document at a time and a question is needed, check this process on the diagram below:
48+
- `POST /resources/docs`
49+
- `POST /genai/search-in-documents`
50+
51+
On `/resources/docs` the documents are uploaded to local system and then broke down into small chunks to be stored on a vector database.
52+
53+
The `/genai/search-in-documents` endpoint uses RAG concept, it's responsible to create an Embedding of the user question, and retrieve the most relevant chunks from vector database using it as context for follow-up questions. Also, it uses Redis to store and retrieve chat history during user's session.
54+
55+
Check this process on the diagram below:
5256

5357
![GenAI Search in Document Flow](docs/genai-flow.png 'GenAI Search in Document Flow')
5458

@@ -80,10 +84,10 @@ cp .env.example .env
8084
> From the app's root directory, run the following command to build and running docker containers:
8185

8286
```shell
83-
docker compose up --build
87+
make run
8488
```
8589

86-
> The application will be available at `http://localhost:3000`.<br>
90+
> The application will be available at `http://localhost:3000`.<br>For more commands see `Makefile` or run `make help`.
8791

8892
## Documentation
8993

@@ -126,3 +130,5 @@ Current supported roles are: [`admin`, `user`]:
126130
| GET status/ | [x] | [x] |
127131
| POST /genai/translate | [x] | [x] |
128132
| POST /genai/search-in-document | [x] | [x] |
133+
| GET /genai/chat-history | [x] | [x] |
134+
| POST /resources/docs | [x] | [x] |

docker-compose.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ services:
88
- '3000:3000'
99
env_file:
1010
- .env
11-
environment:
12-
IS_DOCKER: true
13-
DATABASE_URL: ${DATABASE_URL_DOCKER}
14-
REDIS_URL: ${REDIS_URL_DOCKER}
1511
volumes:
1612
- ./src:/usr/workspace/app/src
1713
- pnpm_store:/pnpm/.pnpm-store
1814
command: sh -c "pnpm migrate:dev && pnpm dev"
1915
depends_on:
2016
- postgres
2117
- redis
18+
- qdrant
2219

2320
postgres:
2421
container_name: genai_app_postgres
@@ -42,7 +39,16 @@ services:
4239
volumes:
4340
- 'genai_app_redis_data:/bitnami/redis/data'
4441

42+
qdrant:
43+
container_name: genai_app_vector_db
44+
image: qdrant/qdrant
45+
ports:
46+
- '6333:6333'
47+
volumes:
48+
- 'genai_app_qdrant_data:/qdrant/storage'
49+
4550
volumes:
4651
pnpm_store:
4752
genai_app_redis_data:
4853
genai_app_postgres_data:
54+
genai_app_qdrant_data:

docs/genai-flow.png

3.01 KB
Loading

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"scripts": {
66
"prestart": "node dynamic-url-config.js",
77
"migrate:dev": "npx prisma migrate dev",
8-
"predev": "node dynamic-url-config.js",
98
"start": "tsx src/app.ts",
109
"dev": "tsx watch src/app.ts",
1110
"postinstall": "npx prisma generate"
@@ -23,8 +22,10 @@
2322
"@langchain/community": "^0.3.1",
2423
"@langchain/core": "^0.3.3",
2524
"@langchain/google-genai": "^0.1.0",
25+
"@langchain/qdrant": "^0.1.1",
2626
"@langchain/redis": "^0.1.0",
2727
"@prisma/client": "5.20.0",
28+
"@qdrant/js-client-rest": "^1.12.0",
2829
"@types/redis": "^4.0.11",
2930
"express": "^4.21.0",
3031
"jsonwebtoken": "^9.0.2",

pnpm-lock.yaml

Lines changed: 61 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)