このバージョンはまだ開発中であり、まだ安定しているとは考えられていません。最新のスナップショットバージョンについては、Spring AI 1.0.3 を使用してください。 |
GemFire ベクトルストア
このセクションでは、ドキュメントの埋め込みを保存し、類似性検索を実行するための GemFireVectorStore の設定について説明します。
GemFire (英語) は、超高速で読み取りおよび書き込み操作を実行する分散型インメモリキーバリューストアです。可用性の高い並列メッセージキュー、継続的な可用性、ダウンタイムなしで動的に拡張できるイベント駆動型アーキテクチャを提供します。高性能なリアルタイムアプリをサポートするためにデータサイズ要件が増大しても、GemFire は簡単に線形に拡張できます。
GemFire ベクトル DB (英語) は GemFire の機能を継承し、ベクトル類似性検索を効率的に保存、取得、実行する多目的ベクトルデータベースとして機能します。
前提条件
GemFire VectorDB 拡張機能が有効になっている GemFire クラスター
ドキュメントの埋め込みを計算するための
EmbeddingModelBean。詳細については、EmbeddingModel セクションを参照してください。マシン上でローカルに実行されるオプションは、ONNX と all-MiniLM-L6-v2 Sentence Transformers です。
自動構成
Spring AI 自動構成、スターターモジュールのアーティファクト名に大きな変更がありました。詳細については、アップグレードノートを参照してください。 |
GemFire VectorStore Spring Boot スターターをプロジェクトの Maven ビルドファイル pom.xml に追加します。
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-vector-store-gemfire</artifactId>
</dependency> または Gradle build.gradle ファイルに
dependencies {
implementation 'org.springframework.ai:spring-ai-starter-vector-store-gemfire'
}構成プロパティ
Spring Boot 構成で次のプロパティを使用して、GemFireVectorStore をさらに構成できます。
| プロパティ | デフォルト値 |
|---|---|
| localhost |
| 8080 |
|
|
| spring-ai-gemfire-store |
| 100 |
| 16 |
| COSINE |
| [] |
| 0 |
手動構成
Spring Boot の自動構成を使用せずに GemFireVectorStore のみを使用するには、プロジェクトの Maven pom.xml に次の依存関係を追加します。
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-gemfire-store</artifactId>
</dependency>Gradle ユーザーの場合は、GemFireVectorStore のみを使用するために、依存関係ブロックの build.gradle ファイルに以下を追加します。
dependencies {
implementation 'org.springframework.ai:spring-ai-gemfire-store'
}使用方法
AutoConfiguration を使用する代わりに GemfireVectorStore のインスタンスを作成するサンプルです
@Bean
public GemFireVectorStore vectorStore(EmbeddingModel embeddingModel) {
return GemFireVectorStore.builder(embeddingModel)
.host("localhost")
.port(7071)
.indexName("my-vector-index")
.fields(new String[] {"country", "year", "activationDate"}) // Optional: fields for metadata filtering
.initializeSchema(true)
.build();
} デフォルト構成では、 |
アプリケーションで、いくつかのドキュメントを作成します。
List<Document> documents = List.of(
new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("country", "UK", "year", 2020)),
new Document("The World is Big and Salvation Lurks Around the Corner", Map.of()),
new Document("You walk forward facing the past and you turn back toward the future.", Map.of("country", "NL", "year", 2023)));ドキュメントをベクトルストアに追加します。
vectorStore.add(documents);類似検索を使用してドキュメントを取得するには:
List<Document> results = vectorStore.similaritySearch(
SearchRequest.builder().query("Spring").topK(5).build());"Spring AI rocks!!" というテキストを含むドキュメントを取得する必要があります。
類似度のしきい値を使用して結果の数を制限することもできます。
List<Document> results = vectorStore.similaritySearch(
SearchRequest.builder().query("Spring").topK(5)
.similarityThreshold(0.5d).build());メタデータフィルタリング
GemFire VectorStore でも、汎用的でポータブルなメタデータフィルターを活用できます。
例: 次のいずれかのテキスト式言語を使用できます。
vectorStore.similaritySearch(SearchRequest.builder()
.query("The World")
.topK(5)
.similarityThreshold(0.7)
.filterExpression("country == 'BG' && year >= 2020").build()); または、Filter.Expression DSL を使用してプログラム的に次のようにします。
FilterExpressionBuilder b = new FilterExpressionBuilder();
vectorStore.similaritySearch(SearchRequest.builder()
.query("The World")
.topK(5)
.similarityThreshold(0.7)
.filterExpression(b.and(
b.eq("country", "BG"),
b.gte("year", 2020)).build()).build());| これらの (ポータブル) フィルター式は、独自の GemFire VectorDB クエリ形式に自動的に変換されます。 |
例: この移植可能なフィルター式:
country == 'BG' && year >= 2020独自の GemFire VectorDB フィルター形式に変換されます。
country:BG AND year:[2020 TO *]
GemFire VectorStore は、幅広いフィルター操作をサポートしています。
等価 :
country == 'BG'→country:BG不等価 :
city != 'Sofia'→city: NOT Sofia次の値より大きい :
year > 2020→year:{2020 TO *]以上 :
year >= 2020→year:[2020 TO *]次の値より小さい :
year < 2025→year:[* TO 2025}次の値以下 :
year ⇐ 2025→year:[* TO 2025]入力 :
country in ['BG', 'NL']→country:(BG OR NL)NOT IN :
country nin ['BG', 'NL']→NOT country:(BG OR NL)AND/OR : 条件を組み合わせるための論理演算子
グループ化 : 複雑な式には括弧を使用する
日付フィルタリング : ISO 8601 形式の日付値 (例:
2024-01-07T14:29:12Z)
GemFire VectorStore でメタデータフィルタリングを使用するには、ベクトルストアの作成時にフィルタリング可能なメタデータフィールドを指定する必要があります。これは、ビルダーの または構成プロパティ経由で: |