Skip to content

Commit bc5411a

Browse files
committed
Adding metadata filtering docs for Gemfire vectorstore
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
1 parent 833a856 commit bc5411a

File tree

1 file changed

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

1 file changed

+79
-5
lines changed

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

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,12 @@ public GemFireVectorStore vectorStore(EmbeddingModel embeddingModel) {
9494
.host("localhost")
9595
.port(7071)
9696
.indexName("my-vector-index")
97+
.fields(new String[] {"country", "year", "activationDate"}) // Optional: fields for metadata filtering
9798
.initializeSchema(true)
9899
.build();
99100
}
100101
----
101102

102-
[NOTE]
103-
====
104-
The GemFire VectorStore does not yet support xref:api/vectordbs.adoc#metadata-filters[metadata filters].
105-
====
106-
107103
[NOTE]
108104
====
109105
The default configuration connects to a GemFire cluster at `localhost:8080`
@@ -144,3 +140,81 @@ List<Document> results = vectorStore.similaritySearch(
144140
.similarityThreshold(0.5d).build());
145141
----
146142

143+
== Metadata Filtering
144+
145+
You can leverage the generic, portable xref:api/vectordbs.adoc#metadata-filters[metadata filters] with GemFire VectorStore as well.
146+
147+
For example, you can use either the text expression language:
148+
149+
[source,java]
150+
----
151+
vectorStore.similaritySearch(SearchRequest.builder()
152+
.query("The World")
153+
.topK(5)
154+
.similarityThreshold(0.7)
155+
.filterExpression("country == 'BG' && year >= 2020").build());
156+
----
157+
158+
or programmatically using the `Filter.Expression` DSL:
159+
160+
[source,java]
161+
----
162+
FilterExpressionBuilder b = new FilterExpressionBuilder();
163+
164+
vectorStore.similaritySearch(SearchRequest.builder()
165+
.query("The World")
166+
.topK(5)
167+
.similarityThreshold(0.7)
168+
.filterExpression(b.and(
169+
b.eq("country", "BG"),
170+
b.gte("year", 2020)).build()).build());
171+
----
172+
173+
NOTE: Those (portable) filter expressions get automatically converted into the proprietary GemFire VectorDB query format.
174+
175+
For example, this portable filter expression:
176+
177+
[source,sql]
178+
----
179+
country == 'BG' && year >= 2020
180+
----
181+
182+
is converted into the proprietary GemFire VectorDB filter format:
183+
184+
----
185+
country:BG AND year:[2020 TO *]
186+
----
187+
188+
The GemFire VectorStore supports a wide range of filter operations:
189+
190+
* **Equality**: `country == 'BG'` → `country:BG`
191+
* **Inequality**: `city != 'Sofia'` → `city: NOT Sofia`
192+
* **Greater Than**: `year > 2020` → `year:{2020 TO *]`
193+
* **Greater Than or Equal**: `year >= 2020` → `year:[2020 TO *]`
194+
* **Less Than**: `year < 2025` → `year:[* TO 2025}`
195+
* **Less Than or Equal**: `year <= 2025` → `year:[* TO 2025]`
196+
* **IN**: `country in ['BG', 'NL']` → `country:(BG OR NL)`
197+
* **NOT IN**: `country nin ['BG', 'NL']` → `NOT country:(BG OR NL)`
198+
* **AND/OR**: Logical operators for combining conditions
199+
* **Grouping**: Use parentheses for complex expressions
200+
* **Date Filtering**: Date values in ISO 8601 format (e.g., `2024-01-07T14:29:12Z`)
201+
202+
[IMPORTANT]
203+
====
204+
To use metadata filtering with GemFire VectorStore, you must specify the metadata fields that can be filtered when creating the vector store. This is done using the `fields` parameter in the builder:
205+
206+
[source,java]
207+
----
208+
GemFireVectorStore.builder(embeddingModel)
209+
.fields(new String[] {"country", "year", "activationDate"})
210+
.build();
211+
----
212+
213+
Or via configuration properties:
214+
215+
[source,properties]
216+
----
217+
spring.ai.vectorstore.gemfire.fields=country,year,activationDate
218+
----
219+
====
220+

0 commit comments

Comments
 (0)