Skip to content

Commit 38546a8

Browse files
authored
Merge pull request #45 from TheovanKraay/java-langchain-vcore
java langchain sample for mongo vCore
2 parents f0c5890 + f9078a8 commit 38546a8

File tree

4 files changed

+426
-0
lines changed

4 files changed

+426
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Use Azure Cosmos DB Mongo vCore with Langchain in Java.
2+
3+
This sample provides a demo showcasing the usage of the RAG pattern for integrating Azure Open AI services with custom data in Azure Cosmos DB MongoDB vCore, using langchain framework for java (https://github.com/langchain4j/langchain4j).
4+
5+
### Prerequisites
6+
7+
- Azure Cosmos DB Monogo Account
8+
- Connection string
9+
- Azure Open AI Service
10+
- Deploy text-davinci-003 model for Embeding
11+
- Deploy gpt-35-turbo model for Chat Completion
12+
13+
14+
### Installation
15+
``` bash
16+
mvn install
17+
```
18+
19+
### Run
20+
21+
Before running the application, you need to set environment variables. Either export them in command line or set system variables:
22+
23+
```bash
24+
export COSMOS_URI_HNSW="Cosmos DB MongoDB vCore connection string"
25+
export AZURE_OPENAI_ENDPOINT="endpoint for your Azure OpenAI account"
26+
export AZURE_OPENAI_APIKEY="key for your Azure OpenAI account"
27+
export AZURE_OPENAI_CHATDEPLOYMENTID="deployment id for your Azure OpenAI chat embeddings"
28+
export AZURE_OPENAI_EMBEDDINGDEPLOYMENTID="deployment is for your Azure OpenAI chat completions"
29+
```
30+
31+
Then run the app:
32+
33+
```bash
34+
mvn exec:java
35+
```
36+
37+
## Getting Started
38+
When you run the application for the first time, it will read and vectorize docs in the `PDF_docs` folder, and insert them into Cosmos DB MongoDB vCore vector store. To begin, just ask a question in command line.
39+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>dev.langchain4j</groupId>
8+
<artifactId>langchain4j-parent</artifactId>
9+
<version>0.29.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>langchain4j-azure-cosmos-vcore</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<name>LangChain4j :: Integration :: Azure CosmosDB MongoDB vCore</name>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>dev.langchain4j</groupId>
20+
<artifactId>langchain4j-azure-cosmos-mongo-vcore</artifactId>
21+
<version>0.29.0</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>dev.langchain4j</groupId>
25+
<artifactId>langchain4j</artifactId>
26+
<version>0.29.0</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>dev.langchain4j</groupId>
30+
<artifactId>langchain4j-core</artifactId>
31+
<version>0.30.0</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.mongodb</groupId>
35+
<artifactId>mongodb-driver-sync</artifactId>
36+
<version>4.11.1</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.projectlombok</groupId>
40+
<artifactId>lombok</artifactId>
41+
<scope>provided</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.slf4j</groupId>
45+
<artifactId>slf4j-api</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter-engine</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.assertj</groupId>
54+
<artifactId>assertj-core</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>dev.langchain4j</groupId>
59+
<artifactId>langchain4j-embeddings-all-minilm-l6-v2-q</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.testcontainers</groupId>
64+
<artifactId>junit-jupiter</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.testcontainers</groupId>
69+
<artifactId>mongodb</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.tinylog</groupId>
74+
<artifactId>tinylog-impl</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.tinylog</groupId>
79+
<artifactId>slf4j-tinylog</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
<dependency>
83+
<groupId>dev.langchain4j</groupId>
84+
<artifactId>langchain4j-document-parser-apache-pdfbox</artifactId>
85+
<version>0.31.0</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>dev.langchain4j</groupId>
89+
<artifactId>langchain4j-azure-open-ai</artifactId>
90+
<version>0.29.0</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>dev.langchain4j</groupId>
94+
<artifactId>langchain4j-open-ai</artifactId>
95+
<version>0.31.0</version>
96+
</dependency>
97+
</dependencies>
98+
<build>
99+
<plugins>
100+
<plugin>
101+
<groupId>org.codehaus.mojo</groupId>
102+
<artifactId>exec-maven-plugin</artifactId>
103+
<version>3.0.0</version>
104+
<configuration>
105+
<mainClass>azure.cosmos.mongo.vcore.demo.AzureCosmosDBMongoVCoreLangchainDemo</mainClass>
106+
</configuration>
107+
</plugin>
108+
<plugin>
109+
<artifactId>maven-compiler-plugin</artifactId>
110+
<version>3.8.1</version>
111+
<configuration>
112+
<source>17</source>
113+
<target>17</target>
114+
</configuration>
115+
</plugin>
116+
</plugins>
117+
</build>
118+
</project>
Binary file not shown.

0 commit comments

Comments
 (0)