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
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"));
95
-
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
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"));
95
+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
96
+
System.out.println(qr);
97
+
} catch (Exception e) {
98
+
System.out.println(e);
99
+
}
99
100
}
100
-
}
101
101
}
102
102
```
103
103
104
104
### Example OpenAI Embedding Function
105
105
106
-
In this example we rely on `tech.amikos.chromadb.embeddings.openai.OpenAIEmbeddingFunction` to generate embeddings for our documents.
106
+
In this example we rely on `tech.amikos.chromadb.embeddings.openai.OpenAIEmbeddingFunction` to generate embeddings for
107
+
our documents.
107
108
108
109
| **Important**: Ensure you have `OPENAI_API_KEY` environment variable set
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"));
135
-
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
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"));
136
+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
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"));
206
-
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
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"));
208
+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
209
+
System.out.println(qr);
210
+
} catch (Exception e) {
211
+
e.printStackTrace();
212
+
System.out.println(e);
213
+
}
211
214
}
212
-
}
213
215
}
214
216
```
215
217
@@ -221,7 +223,10 @@ The above should output:
221
223
222
224
### Example Hugging Face Sentence Transformers Embedding Function
223
225
224
-
In this example we rely on `tech.amikos.chromadb.embeddings.hf.HuggingFaceEmbeddingFunction` to generate embeddings for our documents.
226
+
#### Hugging Face Inference API
227
+
228
+
In this example we rely on `tech.amikos.chromadb.embeddings.hf.HuggingFaceEmbeddingFunction` to generate embeddings for
229
+
our documents using HuggingFace cloud-based inference API.
225
230
226
231
| **Important**: Ensure you have `HF_API_KEY` environment variable set
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"));
253
-
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
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"));
257
+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
258
+
System.out.println(qr);
259
+
} catch (Exception e) {
260
+
System.out.println(e);
261
+
}
257
262
}
258
-
}
259
263
}
260
264
```
261
265
@@ -265,6 +269,63 @@ The above should output:
265
269
{"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]]}
266
270
```
267
271
272
+
#### Hugging Face Text Embedding Inference (HFEI) API
273
+
274
+
In this example we'll use a local Docker based server to generate the embeddings with
275
+
`Snowflake/snowflake-arctic-embed-s` mode.
276
+
277
+
First let's start the HFEI server:
278
+
279
+
```bash
280
+
docker run -d -p 8008:80 --platform linux/amd64 --name hfei ghcr.io/huggingface/text-embeddings-inference:cpu-1.5.0 --model-id Snowflake/snowflake-arctic-embed-s --revision main
281
+
```
282
+
283
+
> Note: Check the official documentation for more details - https://github.com/huggingface/text-embeddings-inference
284
+
285
+
Then we can use the following code to generate embeddings. Note the use of
286
+
`new HuggingFaceEmbeddingFunction.WithAPIType(HuggingFaceEmbeddingFunction.APIType.HFEI_API));` to define the API type,
287
+
this will ensure the client uses the correct endpoint.
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"));
314
+
Collection.QueryResponse qr = collection.query(Arrays.asList("Who is the spy"), 10, null, null, null);
315
+
System.out.println(qr);
316
+
} catch (Exception e) {
317
+
System.out.println(e);
318
+
}
319
+
}
320
+
}
321
+
```
322
+
323
+
The above should similar to the following output:
324
+
325
+
```bash
326
+
{"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.19665092,0.42433012]]}
327
+
```
328
+
268
329
### Ollama Embedding Function
269
330
270
331
In this example we rely on `tech.amikos.chromadb.embeddings.ollama.OllamaEmbeddingFunction` to generate embeddings for
0 commit comments