Class PgVectorStore
java.lang.Object
org.springframework.ai.vectorstore.PgVectorStore
- All Implemented Interfaces:
Consumer<List<Document>>,DocumentWriter,VectorStore,org.springframework.beans.factory.InitializingBean
public class PgVectorStore
extends Object
implements VectorStore, org.springframework.beans.factory.InitializingBean
Uses the "vector_store" table to store the Spring AI vector data. The table and the
vector index will be auto-created if not available.
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefaults to CosineDistance.static enumBy default, pgvector performs exact nearest neighbor search, which provides perfect recall. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPgVectorStore(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient) PgVectorStore(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient, int dimensions) PgVectorStore(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient, int dimensions, PgVectorStore.PgDistanceType distanceType, boolean removeExistingVectorStoreTable, PgVectorStore.PgIndexType createIndexMethod) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds list ofDocuments to the vector store.voidDeletes documents from the vector store.embeddingDistance(String query) similaritySearch(SearchRequest request) Retrieves documents by query embedding similarity and metadata filters to retrieve exactly the number of nearest-neighbor results that match the request criteria.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.vectorstore.VectorStore
accept, similaritySearch
-
Field Details
-
OPENAI_EMBEDDING_DIMENSION_SIZE
public static final int OPENAI_EMBEDDING_DIMENSION_SIZE- See Also:
-
INVALID_EMBEDDING_DIMENSION
public static final int INVALID_EMBEDDING_DIMENSION- See Also:
-
VECTOR_TABLE_NAME
- See Also:
-
filterExpressionConverter
-
-
Constructor Details
-
PgVectorStore
public PgVectorStore(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient) -
PgVectorStore
public PgVectorStore(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient, int dimensions) -
PgVectorStore
public PgVectorStore(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient, int dimensions, PgVectorStore.PgDistanceType distanceType, boolean removeExistingVectorStoreTable, PgVectorStore.PgIndexType createIndexMethod)
-
-
Method Details
-
getDistanceType
-
add
Description copied from interface:VectorStoreAdds list ofDocuments to the vector store.- Specified by:
addin interfaceVectorStore- Parameters:
documents- the list of documents to store. Throws an exception if the underlying provider checks for duplicate IDs.
-
delete
Description copied from interface:VectorStoreDeletes documents from the vector store.- Specified by:
deletein interfaceVectorStore- Parameters:
idList- list of document ids for which documents will be removed.- Returns:
-
similaritySearch
Description copied from interface:VectorStoreRetrieves documents by query embedding similarity and metadata filters to retrieve exactly the number of nearest-neighbor results that match the request criteria.- Specified by:
similaritySearchin interfaceVectorStore- Parameters:
request- Search request for set search parameters, such as the query text, topK, similarity threshold and metadata filter expressions.- Returns:
- Returns documents th match the query request conditions.
-
embeddingDistance
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-