InMemoryStore
public class InMemoryStore implements VDBStoreBase
io/agentscope/core/rag/store/InMemoryStore.java:65–287In 记忆存储,负责持久化与读取数据。位于 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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
documentList | List<Document> | 文档列表(类型 `List`)。The document list. |
Mono<Void>io/agentscope/core/rag/store/InMemoryStore.java:84–116search
public Mono<List<Document>> search(SearchDocumentDto searchDocumentDto)
设置搜索。
Performs the search operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
searchDocumentDto | SearchDocumentDto | 搜索文档 Dto(类型 `SearchDocumentDto`)。The search document dto. |
Mono<List<Document>>io/agentscope/core/rag/store/InMemoryStore.java:118–173delete
public Mono<Boolean> delete(String id)
删除数据。
Performs the delete operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。The id. |
Mono<Boolean>io/agentscope/core/rag/store/InMemoryStore.java:175–185size
public int size()
返回大小。
Gets the number of documents currently stored.
intio/agentscope/core/rag/store/InMemoryStore.java:215–217isEmpty
public boolean isEmpty()
判断是否 isEmpty。
Checks if the store is empty.
booleanio/agentscope/core/rag/store/InMemoryStore.java:226–228clear
public void clear()
清空或重置内部状态。
Clears all documents from the store.
io/agentscope/core/rag/store/InMemoryStore.java:236–238getDimensions
public int getDimensions()
获取维度的向量已存储 in 此存储。
Gets the dimension of vectors stored in this store.
intio/agentscope/core/rag/store/InMemoryStore.java:245–247builder
public static Builder builder()
创建新的构建器用于 InMemoryStore。
Creates a new builder for InMemoryStore.
Builderio/agentscope/core/rag/store/InMemoryStore.java:254–256嵌套类详情Nested Class Detail
Builder
public static class BuilderInMemoryStore的构建器。位于 io.agentscope.core.rag.store 包。核心成员包括 dimensions、build。
Builder for InMemoryStore.