Skip to content

Commit 28d23e6

Browse files
committed
Added example of creating embeddings with the Flux API
1 parent 3c0724a commit 28d23e6

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

examples/client-project/build.gradle

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ repositories {
2121

2222
dependencies {
2323
implementation "com.marklogic:flux-api:1.2.0"
24+
implementation "com.marklogic:flux-embedding-model-minilm:1.2.0"
2425
}
2526

2627
tasks.register("runApp", JavaExec) {
@@ -33,6 +34,15 @@ tasks.register("runApp", JavaExec) {
3334
]
3435
}
3536

37+
tasks.register("runEmbeddingExample", JavaExec) {
38+
mainClass = "org.example.ImportWithEmbeddings"
39+
classpath = sourceSets.main.runtimeClasspath
40+
jvmArgs = [
41+
// Required when running on Java 17.
42+
'--add-exports=java.base/sun.nio.ch=ALL-UNNAMED'
43+
]
44+
}
45+
3646
tasks.register("runViaCustomTask") {
3747
description = "Demonstrate how the Flux API can be used via a custom Gradle task. " +
3848
"Depends on the example application used in the Getting Started guide. " +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
3+
*/
4+
package org.example;
5+
6+
import com.marklogic.flux.api.Flux;
7+
8+
public class ImportWithEmbeddings {
9+
10+
public static void main(String[] args) {
11+
// Depends on the example application created in the Getting Started guide.
12+
Flux.importGenericFiles()
13+
.connectionString("flux-example-user:password@localhost:8004")
14+
.from(options -> options
15+
.paths("../../flux-cli/src/test/resources/mixed-files/hello.txt"))
16+
.to(options -> options
17+
.collections("embedder-example")
18+
.permissionsString("flux-example-role,read,flux-example-role,update")
19+
.splitter(splitterOptions -> splitterOptions.text())
20+
.embedder(embedderOptions -> embedderOptions.embedder("minilm"))
21+
)
22+
.execute();
23+
}
24+
25+
}

flux-cli/src/main/java/com/marklogic/flux/api/EmbedderOptions.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@
1111
public interface EmbedderOptions {
1212

1313
/**
14-
* @param name the fully-qualified class name of an implementation of
14+
* Valid values:
15+
* <ul>
16+
* <li>azure</li>
17+
* <li>minilm</li>
18+
* <li>ollama</li>
19+
* </ul>
20+
*
21+
* @param name either one of the abbreviations listed above, or the fully-qualified class name of an implementation of
1522
* {@code java.util.Function<Map<String, String>, dev.langchain4j.model.embedding.EmbeddingModel>} or
16-
* an abbreviation associated with the class name of an implementation.
23+
* an abbreviation associated with the class name of an implementation. Due to a bug in Flux 1.2.0,
24+
* the class name must not contain any uppercase characters. This will be fixed in the next Flux
25+
* release.
1726
* @return
1827
*/
1928
EmbedderOptions embedder(String name);

0 commit comments

Comments
 (0)