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
Modifier and TypeClassDescriptionstatic enum
static enum
By default, pgvector performs exact nearest neighbor search, which provides perfect recall. -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionPgVectorStore
(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 TypeMethodDescriptionvoid
Adds Documents to the vector store.embeddingDistance
(String query) boolean
boolean
similaritySearch
(String query) similaritySearch
(String query, int topK) similaritySearch
(String query, int topK, double similarityThreshold) void
start()
void
stop()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:VectorStore
Adds Documents to the vector store.- Specified by:
add
in 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:
delete
in interfaceVectorStore
-
similaritySearch
- Specified by:
similaritySearch
in interfaceVectorStore
-
similaritySearch
- Specified by:
similaritySearch
in interfaceVectorStore
-
similaritySearch
- Specified by:
similaritySearch
in 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:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in interfaceorg.springframework.context.SmartLifecycle
-