Skip to content

Commit 2ded3f5

Browse files
authored
Merge pull request #47 from TheovanKraay/java-langchain-nosql
Java langchain nosql api vector search sample
2 parents 38546a8 + 3f723ae commit 2ded3f5

File tree

5 files changed

+486
-2
lines changed

5 files changed

+486
-2
lines changed

Java/CosmosDB-MongoDB-vCore-Langchain/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This sample provides a demo showcasing the usage of the RAG pattern for integrat
44

55
### Prerequisites
66

7-
- Azure Cosmos DB Monogo Account
7+
- Azure Cosmos DB Mongo Account
88
- Connection string
99
- Azure Open AI Service
1010
- Deploy text-davinci-003 model for Embeding
@@ -35,5 +35,5 @@ mvn exec:java
3535
```
3636

3737
## 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.
38+
When you run the application for the first time, it will read and vectorize docs in the `PDF_docs` folder (you can add your own pdf or txt docs here), and insert them into Cosmos DB MongoDB vCore vector store. To begin, just ask a question in command line.
3939

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Use Azure Cosmos DB NoSQL API 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 NoSQL API with [vector search using DiskANN index](https://learn.microsoft.com/azure/cosmos-db/nosql/vector-search) and [langchain framework for java](https://github.com/langchain4j/langchain4j).
4+
5+
### Prerequisites
6+
7+
- Azure Cosmos DB NoSQL API Account
8+
- Azure Cosmos DB NoSQL API endpoint
9+
- Azure Cosmos DB NoSQL API key
10+
- Azure Open AI Service
11+
- Deploy text-davinci-003 model for Embeding
12+
- Deploy gpt-35-turbo model for Chat Completion
13+
14+
15+
### Installation
16+
``` bash
17+
mvn clean install
18+
```
19+
20+
### Run
21+
22+
Before running the application, you need to set environment variables. Either export them in command line or set system variables:
23+
24+
```bash
25+
export COSMOSDB_ENDPOINT="Azure Cosmos DB NoSQL API endpoint"
26+
export COSMOSDB_KEY="Azure Cosmos DB NoSQL API key"
27+
export AZURE_OPENAI_ENDPOINT="endpoint for your Azure OpenAI account"
28+
export AZURE_OPENAI_APIKEY="key for your Azure OpenAI account"
29+
export AZURE_OPENAI_CHATDEPLOYMENTID="deployment id for your Azure OpenAI chat embeddings"
30+
export AZURE_OPENAI_EMBEDDINGDEPLOYMENTID="deployment is for your Azure OpenAI chat completions"
31+
```
32+
33+
Then run the app:
34+
35+
```bash
36+
mvn exec:java
37+
```
38+
39+
## Getting Started
40+
When you run the application for the first time, it will read and vectorize docs in the `PDF_docs` folder (you can add your own pdf or txt docs here), and insert them into Cosmos DB NoSQL API vector store. To begin, just ask a question in command line. By default, your private data will be used to form a response regardless of it's accuracy (experiment with changing the prompt to change the chat completion behaviour).
41+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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-nosql-sample</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<name>LangChain4j :: Integration :: Azure CosmosDB NoSQL API</name>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>dev.langchain4j</groupId>
20+
<artifactId>langchain4j-azure-cosmos-nosql</artifactId>
21+
<version>0.31.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.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.slf4j</groupId>
40+
<artifactId>slf4j-api</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.junit.jupiter</groupId>
44+
<artifactId>junit-jupiter-engine</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.assertj</groupId>
49+
<artifactId>assertj-core</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>dev.langchain4j</groupId>
54+
<artifactId>langchain4j-embeddings-all-minilm-l6-v2-q</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.testcontainers</groupId>
59+
<artifactId>junit-jupiter</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.testcontainers</groupId>
64+
<artifactId>mongodb</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.tinylog</groupId>
69+
<artifactId>tinylog-impl</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.tinylog</groupId>
74+
<artifactId>slf4j-tinylog</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>dev.langchain4j</groupId>
79+
<artifactId>langchain4j-document-parser-apache-pdfbox</artifactId>
80+
<version>0.31.0</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>dev.langchain4j</groupId>
84+
<artifactId>langchain4j-azure-open-ai</artifactId>
85+
<version>0.29.0</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>dev.langchain4j</groupId>
89+
<artifactId>langchain4j-open-ai</artifactId>
90+
<version>0.31.0</version>
91+
</dependency>
92+
</dependencies>
93+
<build>
94+
<plugins>
95+
<plugin>
96+
<groupId>org.codehaus.mojo</groupId>
97+
<artifactId>exec-maven-plugin</artifactId>
98+
<version>3.0.0</version>
99+
<configuration>
100+
<mainClass>azure.cosmos.nosql.demo.AzureCosmosDBNoSQLLangchainDemo</mainClass>
101+
</configuration>
102+
</plugin>
103+
<plugin>
104+
<artifactId>maven-compiler-plugin</artifactId>
105+
<version>3.8.1</version>
106+
<configuration>
107+
<source>17</source>
108+
<target>17</target>
109+
</configuration>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
</project>

0 commit comments

Comments
 (0)