Skip to content

Commit df49126

Browse files
authored
feat: Release 0.1.6 (#45)
1 parent 0efe5a5 commit df49126

File tree

2 files changed

+161
-84
lines changed

2 files changed

+161
-84
lines changed

README.md

+160-82
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ This client works with Chroma Versions `0.4.3+`
88

99
### Embeddings Support
1010

11-
- [x] OpenAI API
12-
- [x] Cohere API (including Multi-language support)
11+
- ✅ Default Embedding Function (all-mini-lm model)
12+
- ✅ OpenAI Embedding Function
13+
- ✅ Cohere Embedding Function
14+
- ✅ HuggingFace Embedding Function
15+
- ✅ Ollama Embedding Function
1316
- [ ] Sentence Transformers
1417
- [ ] PaLM API
1518
- [ ] Custom Embedding Function
@@ -36,7 +39,7 @@ This client works with Chroma Versions `0.4.3+`
3639

3740
- [x] Push the package to Maven
3841
Central - https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven
39-
- ⚒️ Fluent API - make it easier for users to make use of the library
42+
- ⚒️ Fluent API - make it easier for users to make use of the library
4043
- [ ] Support for PaLM API
4144
- [x] Support for Sentence Transformers with Hugging Face API
4245
- ⚒️ Authentication ⚒️
@@ -46,10 +49,11 @@ This client works with Chroma Versions `0.4.3+`
4649
Add Maven dependency:
4750

4851
```xml
52+
4953
<dependency>
5054
<groupId>io.github.amikos-tech</groupId>
5155
<artifactId>chromadb-java-client</artifactId>
52-
<version>0.1.5</version>
56+
<version>0.1.6</version>
5357
</dependency>
5458
```
5559

@@ -59,6 +63,43 @@ Ensure you have a running instance of Chroma running. We recommend one of the tw
5963
- If you are a fan of Kubernetes, you can use the Helm chart - https://github.com/amikos-tech/chromadb-chart (Note: You
6064
will need `Docker`, `minikube` and `kubectl` installed)
6165

66+
### Default Embedding Function
67+
68+
Since version `0.1.6` the library also offers a built-in default embedding function which does not rely on any external
69+
API to generate embeddings and works in the same way it works in core Chroma Python package.
70+
71+
```java
72+
package tech.amikos;
73+
74+
import tech.amikos.chromadb.*;
75+
import tech.amikos.chromadb.Collection;
76+
77+
import java.util.*;
78+
79+
public class Main {
80+
public static void main(String[] args) {
81+
try {
82+
Client client = new Client(System.getenv("CHROMA_URL"));
83+
client.reset();
84+
EmbeddingFunction ef = new DefaultEmbeddingFunction();
85+
Collection collection = client.createCollection("test-collection", null, true, ef);
86+
List<Map<String, String>> metadata = new ArrayList<>();
87+
metadata.add(new HashMap<String, String>() {{
88+
put("type", "scientist");
89+
}});
90+
metadata.add(new HashMap<String, String>() {{
91+
put("type", "spy");
92+
}});
93+
collection.add(null, metadata, Arrays.asList("Hello, my name is John. I am a Data Scientist.", "Hello, my name is Bond. I am a Spy."), Arrays.asList("1", "2"));
94+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
95+
System.out.println(qr);
96+
} catch (Exception e) {
97+
System.out.println(e);
98+
}
99+
}
100+
}
101+
```
102+
62103
### Example OpenAI Embedding Function
63104

64105
In this example we rely on `tech.amikos.chromadb.OpenAIEmbeddingFunction` to generate embeddings for our documents.
@@ -81,7 +122,7 @@ public class Main {
81122
try {
82123
Client client = new Client(System.getenv("CHROMA_URL"));
83124
String apiKey = System.getenv("OPENAI_API_KEY");
84-
EmbeddingFunction ef = new OpenAIEmbeddingFunction(apiKey,"text-embedding-3-small");
125+
EmbeddingFunction ef = new OpenAIEmbeddingFunction(apiKey, "text-embedding-3-small");
85126
Collection collection = client.createCollection("test-collection", null, true, ef);
86127
List<Map<String, String>> metadata = new ArrayList<>();
87128
metadata.add(new HashMap<String, String>() {{
@@ -109,7 +150,8 @@ The above should output:
109150

110151
#### Custom OpenAI Endpoint
111152

112-
For endpoints compatible with OpenAI Embeddings API (e.g. [ollama](https://github.com/ollama/ollama)), you can use the following:
153+
For endpoints compatible with OpenAI Embeddings API (e.g. [ollama](https://github.com/ollama/ollama)), you can use the
154+
following:
113155

114156
> Note: We have added a builder to help with the configuration of the OpenAIEmbeddingFunction
115157
@@ -145,28 +187,28 @@ import tech.amikos.chromadb.Collection;
145187
import java.util.*;
146188

147189
public class Main {
148-
public static void main(String[] args) {
149-
try {
150-
Client client = new Client(System.getenv("CHROMA_URL"));
151-
client.reset();
152-
String apiKey = System.getenv("COHERE_API_KEY");
153-
EmbeddingFunction ef = new CohereEmbeddingFunction(apiKey);
154-
Collection collection = client.createCollection("test-collection", null, true, ef);
155-
List<Map<String, String>> metadata = new ArrayList<>();
156-
metadata.add(new HashMap<String, String>() {{
157-
put("type", "scientist");
158-
}});
159-
metadata.add(new HashMap<String, String>() {{
160-
put("type", "spy");
161-
}});
162-
collection.add(null, metadata, Arrays.asList("Hello, my name is John. I am a Data Scientist.", "Hello, my name is Bond. I am a Spy."), Arrays.asList("1", "2"));
163-
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
164-
System.out.println(qr);
165-
} catch (Exception e) {
166-
e.printStackTrace();
167-
System.out.println(e);
190+
public static void main(String[] args) {
191+
try {
192+
Client client = new Client(System.getenv("CHROMA_URL"));
193+
client.reset();
194+
String apiKey = System.getenv("COHERE_API_KEY");
195+
EmbeddingFunction ef = new CohereEmbeddingFunction(apiKey);
196+
Collection collection = client.createCollection("test-collection", null, true, ef);
197+
List<Map<String, String>> metadata = new ArrayList<>();
198+
metadata.add(new HashMap<String, String>() {{
199+
put("type", "scientist");
200+
}});
201+
metadata.add(new HashMap<String, String>() {{
202+
put("type", "spy");
203+
}});
204+
collection.add(null, metadata, Arrays.asList("Hello, my name is John. I am a Data Scientist.", "Hello, my name is Bond. I am a Spy."), Arrays.asList("1", "2"));
205+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
206+
System.out.println(qr);
207+
} catch (Exception e) {
208+
e.printStackTrace();
209+
System.out.println(e);
210+
}
168211
}
169-
}
170212
}
171213
```
172214

@@ -176,8 +218,6 @@ The above should output:
176218
{"documents":[["Hello, my name is Bond. I am a Spy.","Hello, my name is John. I am a Data Scientist."]],"ids":[["2","1"]],"metadatas":[[{"type":"spy"},{"type":"scientist"}]],"distances":[[5112.614,10974.804]]}
177219
```
178220

179-
180-
181221
### Example Hugging Face Sentence Transformers Embedding Function
182222

183223
In this example we rely on `tech.amikos.chromadb.HuggingFaceEmbeddingFunction` to generate embeddings for our documents.
@@ -193,27 +233,27 @@ import tech.amikos.chromadb.Collection;
193233
import java.util.*;
194234

195235
public class Main {
196-
public static void main(String[] args) {
197-
try {
198-
Client client = new Client(System.getenv("CHROMA_URL"));
199-
client.reset();
200-
String apiKey = System.getenv("HF_API_KEY");
201-
EmbeddingFunction ef = new HuggingFaceEmbeddingFunction(apiKey);
202-
Collection collection = client.createCollection("test-collection", null, true, ef);
203-
List<Map<String, String>> metadata = new ArrayList<>();
204-
metadata.add(new HashMap<String, String>() {{
205-
put("type", "scientist");
206-
}});
207-
metadata.add(new HashMap<String, String>() {{
208-
put("type", "spy");
209-
}});
210-
collection.add(null, metadata, Arrays.asList("Hello, my name is John. I am a Data Scientist.", "Hello, my name is Bond. I am a Spy."), Arrays.asList("1", "2"));
211-
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
212-
System.out.println(qr);
213-
} catch (Exception e) {
214-
System.out.println(e);
236+
public static void main(String[] args) {
237+
try {
238+
Client client = new Client(System.getenv("CHROMA_URL"));
239+
client.reset();
240+
String apiKey = System.getenv("HF_API_KEY");
241+
EmbeddingFunction ef = new HuggingFaceEmbeddingFunction(apiKey);
242+
Collection collection = client.createCollection("test-collection", null, true, ef);
243+
List<Map<String, String>> metadata = new ArrayList<>();
244+
metadata.add(new HashMap<String, String>() {{
245+
put("type", "scientist");
246+
}});
247+
metadata.add(new HashMap<String, String>() {{
248+
put("type", "spy");
249+
}});
250+
collection.add(null, metadata, Arrays.asList("Hello, my name is John. I am a Data Scientist.", "Hello, my name is Bond. I am a Spy."), Arrays.asList("1", "2"));
251+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
252+
System.out.println(qr);
253+
} catch (Exception e) {
254+
System.out.println(e);
255+
}
215256
}
216-
}
217257
}
218258
```
219259

@@ -223,6 +263,44 @@ The above should output:
223263
{"documents":[["Hello, my name is Bond. I am a Spy.","Hello, my name is John. I am a Data Scientist."]],"ids":[["2","1"]],"metadatas":[[{"type":"spy"},{"type":"scientist"}]],"distances":[[0.9073759,1.6440368]]}
224264
```
225265

266+
### Ollama Embedding Function
267+
268+
In this example we rely on `tech.amikos.chromadb.embeddings.ollama.OllamaEmbeddingFunction` to generate embeddings for
269+
our documents.
270+
271+
```java
272+
package tech.amikos;
273+
274+
import tech.amikos.chromadb.*;
275+
import tech.amikos.chromadb.embeddings.ollama.OllamaEmbeddingFunction;
276+
import tech.amikos.chromadb.Collection;
277+
278+
import java.util.*;
279+
280+
public class Main {
281+
public static void main(String[] args) {
282+
try {
283+
Client client = new Client(System.getenv("CHROMA_URL"));
284+
client.reset();
285+
EmbeddingFunction ef = new OllamaEmbeddingFunction();
286+
Collection collection = client.createCollection("test-collection", null, true, ef);
287+
List<Map<String, String>> metadata = new ArrayList<>();
288+
metadata.add(new HashMap<String, String>() {{
289+
put("type", "scientist");
290+
}});
291+
metadata.add(new HashMap<String, String>() {{
292+
put("type", "spy");
293+
}});
294+
collection.add(null, metadata, Arrays.asList("Hello, my name is John. I am a Data Scientist.", "Hello, my name is Bond. I am a Spy."), Arrays.asList("1", "2"));
295+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
296+
System.out.println(qr);
297+
} catch (Exception e) {
298+
System.out.println(e);
299+
}
300+
}
301+
}
302+
```
303+
226304
### Example Auth
227305

228306
> Note: This is a workaround until the client overhaul is completed
@@ -238,18 +316,18 @@ import tech.amikos.chromadb.Collection;
238316
import java.util.*;
239317

240318
public class Main {
241-
public static void main(String[] args) {
242-
try {
243-
Client client = new Client(System.getenv("CHROMA_URL"));
244-
String encodedString = Base64.getEncoder().encodeToString("admin:admin".getBytes());
245-
client.setDefaultHeaders(new HashMap<>() {{
246-
put("Authorization", "Basic " + encodedString);
247-
}});
248-
// your code here
249-
} catch (Exception e) {
250-
System.out.println(e);
319+
public static void main(String[] args) {
320+
try {
321+
Client client = new Client(System.getenv("CHROMA_URL"));
322+
String encodedString = Base64.getEncoder().encodeToString("admin:admin".getBytes());
323+
client.setDefaultHeaders(new HashMap<>() {{
324+
put("Authorization", "Basic " + encodedString);
325+
}});
326+
// your code here
327+
} catch (Exception e) {
328+
System.out.println(e);
329+
}
251330
}
252-
}
253331
}
254332
```
255333

@@ -264,18 +342,18 @@ import tech.amikos.chromadb.Collection;
264342
import java.util.*;
265343

266344
public class Main {
267-
public static void main(String[] args) {
268-
try {
269-
Client client = new Client(System.getenv("CHROMA_URL"));
270-
String encodedString = Base64.getEncoder().encodeToString("admin:admin".getBytes());
271-
client.setDefaultHeaders(new HashMap<>() {{
272-
put("Authorization", "Bearer test-token");
273-
}});
274-
// your code here
275-
} catch (Exception e) {
276-
System.out.println(e);
345+
public static void main(String[] args) {
346+
try {
347+
Client client = new Client(System.getenv("CHROMA_URL"));
348+
String encodedString = Base64.getEncoder().encodeToString("admin:admin".getBytes());
349+
client.setDefaultHeaders(new HashMap<>() {{
350+
put("Authorization", "Bearer test-token");
351+
}});
352+
// your code here
353+
} catch (Exception e) {
354+
System.out.println(e);
355+
}
277356
}
278-
}
279357
}
280358
```
281359

@@ -290,18 +368,18 @@ import tech.amikos.chromadb.Collection;
290368
import java.util.*;
291369

292370
public class Main {
293-
public static void main(String[] args) {
294-
try {
295-
Client client = new Client(System.getenv("CHROMA_URL"));
296-
String encodedString = Base64.getEncoder().encodeToString("admin:admin".getBytes());
297-
client.setDefaultHeaders(new HashMap<>() {{
298-
put("X-Chroma-Token", "test-token");
299-
}});
300-
// your code here
301-
} catch (Exception e) {
302-
System.out.println(e);
371+
public static void main(String[] args) {
372+
try {
373+
Client client = new Client(System.getenv("CHROMA_URL"));
374+
String encodedString = Base64.getEncoder().encodeToString("admin:admin".getBytes());
375+
client.setDefaultHeaders(new HashMap<>() {{
376+
put("X-Chroma-Token", "test-token");
377+
}});
378+
// your code here
379+
} catch (Exception e) {
380+
System.out.println(e);
381+
}
303382
}
304-
}
305383
}
306384
```
307385

pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<name>Chroma Vector DB Java Client Library</name>
77
<groupId>io.github.amikos-tech</groupId>
88
<artifactId>chromadb-java-client</artifactId>
9-
<version>0.1.5</version>
9+
<version>0.1.6</version>
1010
<description>
1111
Chroma Vector DB Java Client
1212
</description>
@@ -27,7 +27,6 @@
2727
<name>Amikos Tech OOD</name>
2828
<url>https://amikos.tech</url>
2929
</organization>
30-
3130
<scm>
3231
<connection>scm:git:git://github.com/amikos-tech/chromadb-java-client.git</connection>
3332
<developerConnection>scm:git:ssh://[email protected]:amikos-tech/chromadb-java-client.git</developerConnection>

0 commit comments

Comments
 (0)