AS AgentScopeAPI 手册 / API Reference

MilvusStore

public class MilvusStore implements VDBStoreBase, AutoCloseable
源码Source io/agentscope/core/rag/store/MilvusStore.java:102–1016

Milvus 存储,负责持久化与读取数据。位于 io.agentscope.core.rag.store 包,实现 VDBStoreBase、AutoCloseable。核心成员包括 create、add、search、delete、getClient、getUri。

Milvus vector database store implementation.

This class provides an interface for storing and searching vectors using Milvus, a cloud-native vector database. It implements the VDBStoreBase interface to provide a unified API for vector storage operations.

In Milvus, we use dynamic fields to store the metadata, including the document ID, chunk ID, and original content.

This implementation uses the Milvus Java SDK v2 (io.milvus:milvus-sdk-java). To use this class, add the following dependency:

`<dependency>
<groupId>io.milvus</groupId>
<artifactId>milvus-sdk-java</artifactId>
<version>2.6.16</version>
</dependency>
`

Example usage:

`// Using builder with authentication and timeout options
try (MilvusStore store = MilvusStore.builder()
.uri("http://localhost:19530")
.databaseName("my_database")
.collectionName("my_collection")
.dimensions(1024)
.token("root:Milvus")
.connectTimeoutMs(30000)
.build()) {
store.add(document).block();
List<Document> results = store.search(queryEmbedding, 5).block();
// Store is automatically closed here
}
`

Authentication options:

  • Token-based: Use token("username:password") format

  • Username/Password: Use username() and password() methods

  • No auth: Leave token/username/password empty for local instances

Note: The uri parameter should be a full HTTP URL including protocol and port, for example: "http://localhost:19530" or "https://milvus.example.com:19530"

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
Builder for creating MilvusStore instances with fluent configuration.

方法摘要Method Summary

方法Method说明Description
public static MilvusStore create(String uri, String collectionName, int dimensions) throws VectorStoreException
staticdeprecated
创建并返回实例。
Creates a new MilvusStore with minimal configuration.
public Mono<Void> add(List<Document> documents)
设置添加。
Performs the add operation.
public Mono<List<Document>> search(SearchDocumentDto searchDocumentDto)
设置搜索。
Performs the search operation.
public Mono<Boolean> delete(String docId)
删除数据。
Performs the delete operation.
public MilvusClientV2 getClient() throws VectorStoreException
获取客户端。
Gets the underlying Milvus client for advanced operations.
public String getUri()
获取URI。
Gets the Milvus server URI.
public String getCollectionName()
获取集合名称。
Gets the collection name.
public int getDimensions()
获取向量维度。
Gets the vector dimensions.
public IndexParam.MetricType getMetricType()
获取指标类型。
Gets the metric type used for similarity search.
public String getDatabaseName()
获取数据库名称。
Gets the database name.
public void close()
关闭连接并释放相关资源。
Closes the Milvus client and releases all resources.
public boolean isClosed()
判断是否已关闭。
Checks if this store has been closed.
public static Builder builder()
static
返回构建器实例。
Creates a new builder for constructing MilvusStore instances.

方法详情Method Detail

create

public static MilvusStore create(String uri, String collectionName, int dimensions) throws VectorStoreException
staticdeprecated

创建并返回实例。

Creates a new MilvusStore with minimal configuration.

已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use `MilvusStore#builder()` instead
参数Parameters
名称Name类型Type说明Description
uriStringURI(类型 `String`)。the Milvus server URI (e.g., "http://localhost:19530")
collectionNameString集合到使用的名称。the name of the collection to use
dimensionsint向量维度(类型 `int`)。the dimension of vectors that will be stored
返回Returns MilvusStore
一种新的MilvusStore 实例。a new MilvusStore instance
抛出Throws
  • VectorStoreException 可能抛出 `VectorStoreException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/core/rag/store/MilvusStore.java:208–212

add

public Mono<Void> add(List<Document> documents)

设置添加。

Performs the add operation.

参数Parameters
名称Name类型Type说明Description
documentsList<Document>文档列表(类型 `List`)。The documents.
返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/core/rag/store/MilvusStore.java:214–259

delete

public Mono<Boolean> delete(String docId)

删除数据。

Performs the delete operation.

参数Parameters
名称Name类型Type说明Description
docIdString文档标识(类型 `String`)。The doc id.
返回Returns Mono<Boolean>
返回Mono。Returns mono.
源码Source io/agentscope/core/rag/store/MilvusStore.java:300–323

getClient

public MilvusClientV2 getClient() throws VectorStoreException

获取客户端。

Gets the underlying Milvus client for advanced operations.

返回Returns MilvusClientV2
MilvusClientV2 实例。the MilvusClientV2 instance
抛出Throws
  • VectorStoreException 可能抛出 `VectorStoreException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/core/rag/store/MilvusStore.java:340–343

getUri

public String getUri()

获取URI。

Gets the Milvus server URI.

返回Returns String
返回字符串结果。the URI
源码Source io/agentscope/core/rag/store/MilvusStore.java:732–734

getCollectionName

public String getCollectionName()

获取集合名称。

Gets the collection name.

返回Returns String
集合名称。the collection name
源码Source io/agentscope/core/rag/store/MilvusStore.java:741–743

getDimensions

public int getDimensions()

获取向量维度。

Gets the vector dimensions.

返回Returns int
维度。the dimensions
源码Source io/agentscope/core/rag/store/MilvusStore.java:750–752

getMetricType

public IndexParam.MetricType getMetricType()

获取指标类型。

Gets the metric type used for similarity search.

返回Returns IndexParam.MetricType
指标类型。the metric type
源码Source io/agentscope/core/rag/store/MilvusStore.java:759–761

getDatabaseName

public String getDatabaseName()

获取数据库名称。

Gets the database name.

返回Returns String
数据库名称。the database name
源码Source io/agentscope/core/rag/store/MilvusStore.java:768–770

close

public void close()

关闭连接并释放相关资源。

Closes the Milvus client and releases all resources.

源码Source io/agentscope/core/rag/store/MilvusStore.java:792–816

isClosed

public boolean isClosed()

判断是否已关闭。

Checks if this store has been closed.

返回Returns boolean
返回布尔值,表示判断结果。true if the store has been closed, false otherwise
源码Source io/agentscope/core/rag/store/MilvusStore.java:823–825

builder

public static Builder builder()
static

返回构建器实例。

Creates a new builder for constructing MilvusStore instances.

返回Returns Builder
一种新的构建器实例。a new builder instance
源码Source io/agentscope/core/rag/store/MilvusStore.java:1013–1015

嵌套类详情Nested Class Detail

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.rag.store 包。核心成员包括 uri、collectionName、dimensions、token、username、password。

Builder for creating MilvusStore instances with fluent configuration.

Example usage:

`MilvusStore store = MilvusStore.builder()
.uri("http://localhost:19530")
.collectionName("my_collection")
.dimensions(1024)
.token("root:Milvus")
.connectTimeoutMs(30000)
.metricType(IndexParam.MetricType.COSINE)
.build();
`
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.