Class PgVectorStore
java.lang.Object
org.springframework.ai.vectorstore.PgVectorStore
- All Implemented Interfaces:
VectorStore,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
public class PgVectorStore
extends Object
implements VectorStore, org.springframework.context.SmartLifecycle
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 enumstatic enumBy default, pgvector performs exact nearest neighbor search, which provides perfect recall. -
Field Summary
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
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 Documents to the vector store.embeddingDistance(String query) booleanbooleansimilaritySearch(String query) similaritySearch(String query, int topK) similaritySearch(String query, int topK, double similarityThreshold) voidstart()voidstop()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, stop
-
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:
-
-
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 Documents to the vector store.- Specified by:
addin interfaceVectorStore- Parameters:
documents- the list of documents to store Will throw an exception if the underlying provider checks for duplicate IDs on add
-
delete
- Specified by:
deletein interfaceVectorStore
-
similaritySearch
- Specified by:
similaritySearchin interfaceVectorStore
-
similaritySearch
- Specified by:
similaritySearchin interfaceVectorStore
-
similaritySearch
- Specified by:
similaritySearchin interfaceVectorStore- Parameters:
query- The query to send, it will be converted to an embedding based on the configuration of the vector store.topK- the top 'k' similar resultssimilarityThreshold- the lower bound of the similarity score- Returns:
- similar documents
-
embeddingDistance
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-