Class SimpleVectorStore
java.lang.Object
org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
org.springframework.ai.vectorstore.SimpleVectorStore
- All Implemented Interfaces:
Consumer<List<Document>>,DocumentWriter,VectorStore,VectorStoreRetriever
A simple, in-memory implementation of the VectorStore
interface.
Uses a ConcurrentHashMap to store vectors and their
associated metadata. Map keys are document IDs; values are
SimpleVectorStoreContent instances that encapsulate each document's text,
metadata, and embedding vector.
Similarity search is performed using cosine similarity over all stored vectors. Filter
expressions on document metadata are evaluated via
SimpleVectorStoreFilterExpressionEvaluator.
The store can be persisted to and restored from a JSON file via the
save(java.io.File) and load(java.io.File) /
load(org.springframework.core.io.Resource) methods.
NOTE: This implementation is not designed for production use and should only be used for testing or demonstration purposes.
- Since:
- 1.0.0
- Author:
- Raphael Yu, Dingmeng Xue, Mark Pollack, Christian Tzolov, Sebastien Deleuze, Ilayaperumal Gopinathan, Thomas Vitale, Jemin Huh, David Yu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classNested classes/interfaces inherited from interface org.springframework.ai.vectorstore.VectorStore
VectorStore.Builder<T extends VectorStore.Builder<T>> -
Field Summary
FieldsModifier and TypeFieldDescriptionFields inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
batchingStrategy, embeddingModel -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionbuilder(EmbeddingModel embeddingModel) Creates an instance of SimpleVectorStore builder.createObservationContextBuilder(String operationName) Create a newVectorStoreObservationContext.Builderinstance.voidPerform the actual add operation.voidPerform the actual delete operation.voiddoDelete(Filter.Expression filterExpression) Template method for concrete implementations to provide filter-based deletion logic.doSimilaritySearch(SearchRequest request) Perform the actual similarity search operation.voidDeserialize the vector store content from a file in JSON format into memory.voidload(org.springframework.core.io.Resource resource) Deserialize the vector store content from a resource in JSON format into memory.voidSerialize the vector store content into a file in JSON format.Methods inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
add, delete, delete, similaritySearchMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.document.DocumentWriter
writeMethods inherited from interface org.springframework.ai.vectorstore.VectorStore
accept, delete, getName, getNativeClientMethods inherited from interface org.springframework.ai.vectorstore.VectorStoreRetriever
similaritySearch
-
Field Details
-
store
-
-
Constructor Details
-
SimpleVectorStore
-
-
Method Details
-
builder
Creates an instance of SimpleVectorStore builder.- Returns:
- the SimpleVectorStore builder.
-
doAdd
Description copied from class:AbstractObservationVectorStorePerform the actual add operation.- Specified by:
doAddin classAbstractObservationVectorStore- Parameters:
documents- the documents to add
-
doDelete
Description copied from class:AbstractObservationVectorStorePerform the actual delete operation.- Specified by:
doDeletein classAbstractObservationVectorStore- Parameters:
idList- the list of document IDs to delete
-
doDelete
Description copied from class:AbstractObservationVectorStoreTemplate method for concrete implementations to provide filter-based deletion logic.- Overrides:
doDeletein classAbstractObservationVectorStore- Parameters:
filterExpression- Filter expression to identify documents to delete
-
doSimilaritySearch
Description copied from class:AbstractObservationVectorStorePerform the actual similarity search operation.- Specified by:
doSimilaritySearchin classAbstractObservationVectorStore- Parameters:
request- the search request- Returns:
- the list of documents that match the query request conditions
-
save
Serialize the vector store content into a file in JSON format.- Parameters:
file- the file to save the vector store content
-
load
Deserialize the vector store content from a file in JSON format into memory.- Parameters:
file- the file to load the vector store content
-
load
public void load(org.springframework.core.io.Resource resource) Deserialize the vector store content from a resource in JSON format into memory.- Parameters:
resource- the resource to load the vector store content
-
createObservationContextBuilder
Description copied from class:AbstractObservationVectorStoreCreate a newVectorStoreObservationContext.Builderinstance.- Specified by:
createObservationContextBuilderin classAbstractObservationVectorStore- Parameters:
operationName- the operation name- Returns:
- the observation context builder
-