Skip to content

Commit 0e58b10

Browse files
authored
updated sample code in chroma documentation (#291)
1 parent dfbea8c commit 0e58b10

File tree

1 file changed

+16
-9
lines changed
  • spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs

1 file changed

+16
-9
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/chroma.adoc

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public RestTemplate restTemplate() {
6565
@Bean
6666
public ChromaApi chromaApi(RestTemplate restTemplate) {
6767
String chromaUrl = "http://localhost:8000";
68-
ChromaApi chromaApi = ChromaApi(chromaUrl, restTemplate);
68+
ChromaApi chromaApi = new ChromaApi(chromaUrl, restTemplate);
6969
return chromaApi;
7070
}
7171
----
@@ -101,14 +101,14 @@ Add the documents to your vector store:
101101

102102
[source,java]
103103
----
104-
vectorStore.add(List.of(document));
104+
vectorStore.add(documents);
105105
----
106106

107107
And finally, retrieve documents similar to a query:
108108

109109
[source,java]
110110
----
111-
List<Document> results = vectorStore.similaritySearch("Spring", 5);
111+
List<Document> results = vectorStore.similaritySearch("Spring");
112112
----
113113

114114
If all goes well, you should retrieve the document containing the text "Spring AI rocks!!".
@@ -121,8 +121,12 @@ For example, you can use either the text expression language:
121121

122122
[source,java]
123123
----
124-
vectorStore.similaritySearch("The World", TOP_K, SIMILARITY_THRESHOLD,
125-
"author in ['john', 'jill'] && article_type == 'blog'");
124+
vectorStore.similaritySearch(
125+
SearchRequest.defaults()
126+
.withQuery("The World")
127+
.withTopK(TOP_K)
128+
.withSimilarityThreshold(SIMILARITY_THRESHOLD)
129+
.withFilterExpression("author in ['john', 'jill'] && article_type == 'blog'"));
126130
----
127131

128132
or programmatically using the `Filter.Expression` DSL:
@@ -131,10 +135,13 @@ or programmatically using the `Filter.Expression` DSL:
131135
----
132136
FilterExpressionBuilder b = new FilterExpressionBuilder();
133137
134-
vectorStore.similaritySearch("The World", TOP_K, SIMILARITY_THRESHOLD,
135-
b.and(
136-
b.in(List.of("john", "jill")),
137-
b.eq("article_type", "blog")).build());
138+
vectorStore.similaritySearch(SearchRequest.defaults()
139+
.withQuery("The World")
140+
.withTopK(TOP_K)
141+
.withSimilarityThreshold(SIMILARITY_THRESHOLD)
142+
.withFilterExpression(b.and(
143+
b.in("john", "jill"),
144+
b.eq("article_type", "blog")).build()));
138145
----
139146

140147
NOTE: Those (portable) filter expressions get automatically converted into the proprietary Chroma `where` link:https://docs.trychroma.com/usage-guide#using-where-filters[filter expressions].

0 commit comments

Comments
 (0)