跳到主要内容

Milvus

https://milvus.io/

Maven 依赖

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-milvus</artifactId>
<version>1.0.0-beta3</version>
</dependency>

API

  • MilvusEmbeddingStore

创建

创建 MilvusEmbeddingStore 有 2 种方式:

1. 使用构建器

// 创建 MilvusEmbeddingStore 实例
MilvusEmbeddingStore store = MilvusEmbeddingStore.builder()
.host("localhost") // Milvus 服务器主机
.port(19530) // Milvus 服务器端口
.collectionName("example_collection") // 集合名称
.dimension(128) // 向量维度
.indexType(IndexType.FLAT) // 索引类型
.metricType(MetricType.COSINE) // 度量类型
.consistencyLevel(ConsistencyLevelEnum.EVENTUALLY) // 一致性级别
.autoFlushOnInsert(true) // 插入后自动刷新
.idFieldName("id") // ID 字段名称
.textFieldName("text") // 文本字段名称
.metadataFieldName("metadata") // 元数据字段名称
.vectorFieldName("vector") // 向量字段名称
.build(); // 构建 MilvusEmbeddingStore 实例

2. 使用自定义 Milvus 客户端

// 创建自定义 Milvus 客户端
MilvusServiceClient customMilvusClient = new MilvusServiceClient(
ConnectParam.newBuilder()
.withHost("localhost")
.withPort(19530)
.build()
);

// 在构建器中使用自定义客户端
MilvusEmbeddingStore store = MilvusEmbeddingStore.builder()

.milvusClient(customMilvusClient) // 使用现有的 Milvus 客户端
.collectionName("example_collection") // 集合名称
.dimension(128) // 向量维度
.indexType(IndexType.FLAT) // 索引类型
.metricType(MetricType.COSINE) // 度量类型
.consistencyLevel(ConsistencyLevelEnum.EVENTUALLY) // 一致性级别
.autoFlushOnInsert(true) // 插入后自动刷新
.idFieldName("id") // ID 字段名称
.textFieldName("text") // 文本字段名称
.metadataFieldName("metadata") // 元数据字段名称
.vectorFieldName("vector") // 向量字段名称
.build(); // 构建 MilvusEmbeddingStore 实例


示例