AS AgentScopeAPI 手册 / API Reference

InMemoryStore

public class InMemoryStore implements VDBStoreBase
源码Source io/agentscope/core/rag/store/InMemoryStore.java:65–287

In 记忆存储,负责持久化与读取数据。位于 io.agentscope.core.rag.store 包,实现 VDBStoreBase。核心成员包括 add、search、delete、size、isEmpty、clear。

In-memory implementation of vector database storage.

This implementation stores vectors in memory using a ConcurrentHashMap for thread safety. It uses cosine similarity for vector search, which is the most common metric for embedding vectors.

This implementation is suitable for:

  • Development and testing

  • Small to medium-sized datasets

  • Prototyping RAG systems

For production use with large datasets, consider using a dedicated vector database like Qdrant, ChromaDB, or Pinecone.

Example usage:

`InMemoryStore store = InMemoryStore.builder()
.dimensions(1024)
.build();

// Add documents
store.add(documents).block();

// Search
List<Document> results = store.search(queryEmbedding, 5, 0.8).block();
`

Exception Handling:

  • IllegalArgumentException - for invalid input parameters (null documents, null embeddings, invalid limit)

  • VectorStoreException - for vector-specific errors (dimension mismatch)

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
InMemoryStore的构建器。
Builder for InMemoryStore.

方法摘要Method Summary

方法Method说明Description
public Mono<Void> add(List<Document> documentList)
设置添加。
Performs the add operation.
public Mono<List<Document>> search(SearchDocumentDto searchDocumentDto)
设置搜索。
Performs the search operation.
public Mono<Boolean> delete(String id)
删除数据。
Performs the delete operation.
public int size()
返回大小。
Gets the number of documents currently stored.
public boolean isEmpty()
判断是否 `isEmpty`。
Checks if the store is empty.
public void clear()
清空或重置内部状态。
Clears all documents from the store.
public int getDimensions()
获取维度的向量已存储 in 此存储。
Gets the dimension of vectors stored in this store.
public static Builder builder()
static
创建新的构建器用于 InMemoryStore。
Creates a new builder for InMemoryStore.

方法详情Method Detail

add

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

设置添加。

Performs the add operation.

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

delete

public Mono<Boolean> delete(String id)

删除数据。

Performs the delete operation.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。The id.
返回Returns Mono<Boolean>
返回Mono。Returns mono.
源码Source io/agentscope/core/rag/store/InMemoryStore.java:175–185

size

public int size()

返回大小。

Gets the number of documents currently stored.

返回Returns int
返回数值结果。the number of stored documents (always non-negative)
源码Source io/agentscope/core/rag/store/InMemoryStore.java:215–217

isEmpty

public boolean isEmpty()

判断是否 isEmpty。

Checks if the store is empty.

返回Returns boolean
返回布尔值,表示判断结果。true if the store contains no documents, false otherwise
源码Source io/agentscope/core/rag/store/InMemoryStore.java:226–228

clear

public void clear()

清空或重置内部状态。

Clears all documents from the store.

源码Source io/agentscope/core/rag/store/InMemoryStore.java:236–238

getDimensions

public int getDimensions()

获取维度的向量已存储 in 此存储。

Gets the dimension of vectors stored in this store.

返回Returns int
向量维度。the vector dimension
源码Source io/agentscope/core/rag/store/InMemoryStore.java:245–247

builder

public static Builder builder()
static

创建新的构建器用于 InMemoryStore。

Creates a new builder for InMemoryStore.

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

嵌套类详情Nested Class Detail

Builder

public static class Builder

InMemoryStore的构建器。位于 io.agentscope.core.rag.store 包。核心成员包括 dimensions、build。

Builder for InMemoryStore.

基于官方固定版本源码静态生成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.