You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -37,27 +37,18 @@ In this workshop, we'll explore the fundamentals of custom ChatGPT experiences b
37
37
- Use [Azure OpenAI](https://azure.microsoft.com/products/ai-services/openai-service) models and [LangChain4j](https://langchain4j.github.io/langchain4j/) to generate answers based on a prompt.
38
38
- Query a vector database and augment a prompt to generate responses.
We'll use [GitHub Codespaces](https://github.com/features/codespaces) to have an instant dev environment already prepared for this workshop.
52
+
As for development, you can either use your local environment or [GitHub Codespaces](https://github.com/features/codespaces). Thanks to GitHub Codespaces you can have an instant dev environment already prepared for this workshop.
54
53
55
54
If you prefer to work locally, we'll also provide instructions to setup a local dev environment using either VS Code with a [dev container](https://aka.ms/vscode/ext/devcontainer) or a manual install of the needed tools with your favourite IDE (Intellij IDEA, VS Code, etc.).
56
-
57
-
<divclass="info"data-title="note">
58
-
59
-
> Your Azure account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [Role Based Access Control Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview), [User Access Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#user-access-administrator), or [Owner](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#owner). Your account also needs `Microsoft.Resources/deployments/write` permissions at a subscription level to allow deployment of Azure resources.
60
-
>
61
-
> If you have your own personal Azure subscription, you should be good to go. If you're using an Azure subscription provided by your company, you may need to contact your IT department to ensure you have the necessary permissions.
| Azure account |[Get a free Azure account](https://azure.microsoft.com/free)|
31
+
| Access to Azure OpenAI API |[Request access to Azure OpenAI](https://aka.ms/oaiapply)|
32
+
33
+
<divclass="info"data-title="note">
34
+
35
+
> Your Azure account must have `Microsoft.Authorization/roleAssignments/write` permissions, such as [Role Based Access Control Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#role-based-access-control-administrator-preview), [User Access Administrator](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#user-access-administrator), or [Owner](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#owner). Your account also needs `Microsoft.Resources/deployments/write` permissions at a subscription level to allow deployment of Azure resources.
36
+
>
37
+
> If you have your own personal Azure subscription, you should be good to go. If you're using an Azure subscription provided by your company, you may need to contact your IT department to ensure you have the necessary permissions.
Copy file name to clipboardExpand all lines: docs/sections/java-quarkus/04-vector-db.md
+15-4
Original file line number
Diff line number
Diff line change
@@ -31,13 +31,20 @@ For this workshop, we'll use Qdrant as our vector database as it works well with
31
31
32
32
### Running Qdrant locally
33
33
34
-
To start Qdrant locally, you can use the following command:
34
+
To start Qdrant locally we have setup a Docker Compose file. You can use the following command from the root of the project:
35
35
36
36
```bash
37
-
docker run -p 6333:6333 -v $(pwd)/.qdrant:/qdrant/storage:z qdrant/qdrant:v1.7.3
37
+
docker compose -f infra/docker-compose/qdrant.yml up
38
38
```
39
39
40
-
This will pull the Docker image, start Qdrant on port `6333` and mount a volume to store the data in the `.qdrant` folder.
40
+
This will pull the Docker image, start Qdrant on port `6333` and mount a volume to store the data in the `.qdrant` folder. You should see logs that look like:
41
+
42
+
```text
43
+
qdrant-1 | INFO qdrant::actix: Qdrant HTTP listening on 6333
44
+
qdrant-1 | INFO actix_server::builder: Starting 9 workers
45
+
qdrant-1 | INFO qdrant::tonic: Qdrant gRPC listening on
46
+
qdrant-1 | INFO actix_server::server: Actix runtime found; starting in Actix runtime
47
+
```
41
48
42
49
You can test that Qdrant is running by opening the following URL in your browser: [http://localhost:6333/dashboard](http://localhost:6333/dashboard).
43
50
@@ -48,4 +55,8 @@ You can test that Qdrant is running by opening the following URL in your browser
48
55
49
56
</div>
50
57
51
-
Once you tested that Qdrant is running correctly, you can stop it by pressing `CTRL+C` in your terminal.
58
+
Once you tested that Qdrant is running correctly, you can stop it by pressing `CTRL+C` in your terminal or executing the following command from the root directory of the project:
59
+
60
+
```bash
61
+
docker compose -f infra/docker-compose/qdrant.yml down
Copy file name to clipboardExpand all lines: docs/sections/java-quarkus/05-ingestion.md
+181-37
Original file line number
Diff line number
Diff line change
@@ -16,68 +16,212 @@ PDFs files, which are stored in the `data` folder, will be read by the `Document
16
16
17
17
</div>
18
18
19
+
Create the `DocumentIngestor` under the `src/main/java` directory, inside the `ai.azure.openai.rag.workshop.ingestion` package. The `main` method of the `DocumentIngestor` class looks like the following:
// Setup Qdrant store for embeddings storage and retrieval
29
+
// Load all the PDFs, compute embeddings and store them in Qdrant store
30
+
31
+
System.exit(0);
32
+
}
33
+
}
34
+
```
35
+
36
+
LangChain4j uses [TinyLog](https://tinylog.org) as a logging framework. Create the `src/ingestion-java/src/main/resources/tinylog.properties` and set the log level to `info` (you can also set it to `debug` if you want more logs):
37
+
38
+
```properties
39
+
writer.level = info
40
+
```
41
+
42
+
#### Setup the Qadrant client
43
+
44
+
Now that we have the `DocumentIngestor` class, we need to setup the Qdrant client to interact with the vector database. We'll use the `QdrantEmbeddingStore` class from LangChain4j to interact with Qdrant. Notice the name of the collection (`rag-workshop-collection`), the port (`localhost` as Qdrant is running locally) and th GRPC port (`6334`):
45
+
46
+
```java
47
+
publicclassDocumentIngestor {
48
+
49
+
publicstaticvoidmain(String[] args) {
50
+
51
+
// Setup Qdrant store for embeddings storage and retrieval
52
+
log.info("### Setup Qdrant store for embeddings storage and retrieval");
// Load all the PDFs, compute embeddings and store them in Qdrant store
60
+
61
+
System.exit(0);
62
+
}
63
+
}
64
+
```
65
+
19
66
#### Reading the PDF files content
20
67
21
-
The content the PDFs files will be used as part of the *Retriever* component of the RAG architecture, to generate answers to your questions using the GPT model.
68
+
The content of the PDFs files will be used as part of the *Retriever* component of the RAG architecture, to generate answers to your questions using the GPT model. To read these files we need to iterate through the PDF files located under the classpath. We'll use the `findPdfFiles()` method to get the list of PDF files and then load them with the `FileSystemDocumentLoader` from LangChain4j:
69
+
70
+
```java
71
+
publicclassDocumentIngestor {
72
+
73
+
publicstaticvoidmain(String[] args) {
74
+
75
+
// Setup Qdrant store for embeddings storage and retrieval
76
+
77
+
// Load all the PDFs, compute embeddings and store them in Qdrant store
thrownewRuntimeException("Error reading files from directory", e);
98
+
}
99
+
}
100
+
}
101
+
```
102
+
103
+
#### Split the document into segments
104
+
105
+
Now that the PDF files are loaded, we need to split each PDF file (thanks to `DocumentSplitter`) into smaller chunks, called `TextSegment`:
106
+
107
+
108
+
```java
109
+
publicclassDocumentIngestor {
110
+
111
+
publicstaticvoidmain(String[] args) {
22
112
23
-
Text from the PDF files is extracted in the `DocumentIngestor` using LangChain4j. You can have a look at code of the `extractTextFromPdf()` method if you're curious about how it works.
113
+
// Setup Qdrant store for embeddings storage and retrieval
114
+
115
+
// Load all the PDFs, compute embeddings and store them in Qdrant store
116
+
for (Path pdfFile : pdfFiles) {
117
+
118
+
// ...
119
+
log.info("### Split document into segments 100 tokens each");
After the text is extracted, it's then transformed into embeddings using the [OpenAI JavaScript library](https://github.com/openai/openai-node):
133
+
After the text is extracted into segments, they are then transformed into embeddings using the [AllMiniLmL6V2EmbeddingModel](https://github.com/langchain4j/langchain4j-embeddings) from LangChain4j. This model runs locally in memory (no need to connect to a remote LLM) and generates embeddings for each segment:
134
+
135
+
```java
136
+
publicclassDocumentIngestor {
137
+
138
+
publicstaticvoidmain(String[] args) {
139
+
140
+
// Setup Qdrant store for embeddings storage and retrieval
The embeddings along with the original texts are then added to the vector database using the [QdrantJavaScriptclientlibrary](https://www.npmjs.com/package/@qdrant/qdrant-js). This process is done in batches, to improve performance and limit the number of requests:
Let's now execute this process. First, you need to make sure you have Qdrant and the indexer service running locally. We'lluseDockerComposetorunbothservicesatthesametime. Runthefollowingcommandinaterminal (**makesureyoustoppedtheQdrantcontainerbefore!**):
182
+
Let's now execute this process. First, you need to make sure you have Qdrant running locally and all setup. Run the following command in a terminal to start up Qdrant (**make sure you stopped the Qdrant container before!**):
61
183
62
184
```bash
63
-
docker compose up
185
+
docker compose -f infra/docker-compose/qdrant.yml up
This will start Qdrant locally. Make sure you can access the Qdrant dashboard at the URL http://localhost:6333/dashboard. Then, create a new collection named `rag-workshop-collection` with the following cUrl command:
67
189
68
-
<divclass="tip"data-title="tip">
190
+
```bash
191
+
curl -X PUT 'http://localhost:6333/collections/rag-workshop-collection' \
Once Qdrant is started and the collection is created, you can run the ingestion process by opening a new terminal and running the following Maven command under the `src/ingestion-java` folder. This will compile the code and run the ingestion process by running `DocumentIngestor`:
0 commit comments