AsyncAzurePGVectorStore()LangChain VectorStore backed by Azure Database for PostgreSQL (async).
The store validates or creates the backing table on initialization, and optionally discovers an existing vector index configuration. It supports inserting, deleting, fetching by id, similarity search, and MMR search.
Fields such as schema_name, table_name, and column names control the
schema layout. embedding_type, embedding_dimension, and
embedding_index describe the vector column and its index behavior.
Metadata can be stored in a single JSONB column by passing a string (default
"metadata"), in multiple typed columns via a list of strings/tuples, or
disabled by setting metadata_columns=None.
:param embedding: The embedding model to use for embedding vector generation. :type embedding: Embeddings | None :param connection: The database connection or connection pool to use. :type connection: AsyncConnection | AsyncConnectionPool :param schema_name: The name of the database schema to use. :type schema_name: str :param table_name: The name of the database table to use. :type table_name: str :param id_column: The name of the column containing document IDs (UUIDs). :type id_column: str :param content_column: The name of the column containing document content. :type content_column: str :param embedding_column: The name of the column containing document embeddings. :type embedding_column: str :param embedding_type: The type of the embedding vectors. :type embedding_type: VectorType | None :param embedding_dimension: The dimensionality of the embedding vectors. :type embedding_dimension: PositiveInt | None :param embedding_index: The algorithm used for indexing the embedding vectors. :type embedding_index: Algorithm | None :param _embedding_index_name: (internal) The name of the discovered or created index. :type _embedding_index_name: str | None :param metadata_columns: The columns to use for storing metadata. :type metadata_columns: list[str] | list[tuple[str, str]] | str | None
Create the vector index on the embedding column (if not already exists).
Builds a vector index for the configured embedding_column using the
algorithm specified by embedding_index (DiskANN, HNSW or
IVFFlat). The effective index type name is inferred from the
concrete Algorithm instance and the index name is generated as
<table>_<column>_<type>_idx. If an index has already been discovered
(_embedding_index_name is not None) the operation is skipped.
Prior to executing create index the per-build tuning parameters
(returned by :meth:Algorithm.index_settings) are applied via set
GUCs so they only affect this session. Build-time options (returned by
:meth:Algorithm.build_settings) are appended in a with (...)
clause.
For quantized operator classes:
halfvec_* (scalar quantization) casts both the stored column and
future query vectors to halfvec(dim).bit_* (binary quantization) wraps the column with
binary_quantize(col)::bit(dim).
Otherwise the raw column is indexed.:param concurrently: When True uses create index concurrently to
avoid long write-locks at the expense of a slower build.
:type concurrently: bool
:return: True if the index was created, False when an existing
index prevented creation.
:rtype: bool
:raises AssertionError: If required attributes (embedding_index or
embedding_dimension) are unexpectedly None.
Reindex the existing vector index.
Issues a reindex (concurrently <bool>, verbose <bool>) index command
for the previously discovered or created index (tracked in
_embedding_index_name). The session-level index tuning GUCs
(returned by :meth:Algorithm.index_settings) are applied beforehand to
influence the reindex process (useful for algorithms whose maintenance
cost or accuracy depends on these settings).
:param concurrently: When True performs a concurrent reindex to
minimize locking, trading speed for availability.
:type concurrently: bool
:param verbose: When True enables PostgreSQL verbose output, which
may aid in diagnosing build performance issues.
:type verbose: bool
:return: True if reindex succeeded, False if no index existed.
:rtype: bool
:raises AssertionError: If embedding_index is unexpectedly None.
Create a store and add documents in one step.
:param documents: The list of documents to add to the store. :type documents: list[Document] :param embedding: The embedding model to use for embedding vector generation. :type embedding: Embeddings
:return: The created vector store instance. :rtype: Self
Create a store and add texts with optional metadata.
:param texts: The list of texts to add to the store.
:type texts: list[str]
:param embedding: The embedding model to use for embedding vector generation.
:type embedding: Embeddings
:param metadatas: The list of metadata dictionaries corresponding to each text.
:type metadatas: list[dict] | None
:param ids: The list of custom IDs corresponding to each text. When ids
are not provided, UUIDs are generated.
:type ids: list[str] | None
See :meth:afrom_documents for required and/or supported kwargs.
:return: The created vector store instance. :rtype: Self
Insert or upsert a batch of LangChain documents.
:return: Inserted ids. :rtype: list[str]
Insert or upsert texts with optional metadatas and embeddings.
If an embeddings model is present, embeddings are computed and stored. When
metadata_columns is a string, metadata is written as JSONB; otherwise only
provided keys matching configured columns are stored.
:return: Inserted ids. :rtype: list[str] :raises ValueError: If the length of 'metadatas', 'texts', and 'ids' do not match.
Delete by ids or truncate the table.
If ids is None, the table is truncated.
:return: True if the operation was successful, False otherwise. :rtype: bool | None
Fetch documents by their ids.
:param ids: Sequence of string ids. :type ids: Sequence[str] :return: Documents with metadata reconstructed from configured columns. :rtype: list[Document]
Similarity search for a query string using the configured index.
:param query: Query text to embed and search. :type query: str :param k: Number of most similar documents. :type k: int
:return: Top-k documents. :rtype: list[Document]
Similarity search returning (document, distance) pairs.
:param query: Query text to embed and search. :type query: str :param k: Number of most similar documents. :type k: int
See :meth:asimilarity_search for supported kwargs.
:return: Top-k (document, distance) pairs. :rtype: list[tuple[Document, float]]
Similarity search for a precomputed embedding vector.
:param embedding: The precomputed embedding vector to search for. :type embedding: list[float] :param k: Number of most similar documents. :type k: int
See :meth:asimilarity_search for supported kwargs.
:return: Top-k documents. :rtype: list[Document]
MMR search for a query string.
:param query: The query string to search for. :type query: str :param k: Number of most similar documents to return. :type k: int :param fetch_k: Candidate pool size before MMR reranking. :type fetch_k: int :param lambda_mult: Diversity vs. relevance trade-off parameter. :type lambda_mult: float
See :meth:similarity_search for supported kwargs.
:return: Top-k documents. :rtype: list[Document]
MMR search for a precomputed embedding vector.
:param embedding: The precomputed embedding vector to search for. :type embedding: list[float] :param k: Number of most similar documents to return. :type k: int :param fetch_k: Candidate pool size before MMR reranking. :type fetch_k: int :param lambda_mult: Diversity vs. relevance trade-off parameter. :type lambda_mult: float
See :meth:similarity_search for supported kwargs.
:return: Top-k documents. :rtype: list[Document]