Class AlloyDBVectorStore (0.4.0)

AlloyDBVectorStore(
    key: object,
    engine: langchain_google_alloydb_pg.alloydb_engine.AlloyDBEngine,
    embedding_service: langchain_core.embeddings.embeddings.Embeddings,
    table_name: str,
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: typing.List[str] = [],
    id_column: str = "langchain_id",
    metadata_json_column: typing.Optional[str] = "langchain_metadata",
    distance_strategy: langchain_google_alloydb_pg.indexes.DistanceStrategy = DistanceStrategy.COSINE_DISTANCE,
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    index_query_options: typing.Optional[
        langchain_google_alloydb_pg.indexes.QueryOptions
    ] = None,
)

Google AlloyDB Vector Store class

Properties

embeddings

Access the query embedding object if available.

Methods

aadd_documents

aadd_documents(
    documents: typing.List[langchain_core.documents.base.Document],
    ids: typing.Optional[typing.List[str]] = None,
    **kwargs: typing.Any
) -> typing.List[str]

Run more documents through the embeddings and add to the vectorstore.

aadd_texts

aadd_texts(
    texts: typing.Iterable[str],
    metadatas: typing.Optional[typing.List[dict]] = None,
    ids: typing.Optional[typing.List[str]] = None,
    **kwargs: typing.Any
) -> typing.List[str]

Run more texts through the embeddings and add to the vectorstore.

add_documents

add_documents(
    documents: typing.List[langchain_core.documents.base.Document],
    ids: typing.Optional[typing.List[str]] = None,
    **kwargs: typing.Any
) -> typing.List[str]

Run more documents through the embeddings and add to the vectorstore.

add_texts

add_texts(
    texts: typing.Iterable[str],
    metadatas: typing.Optional[typing.List[dict]] = None,
    ids: typing.Optional[typing.List[str]] = None,
    **kwargs: typing.Any
) -> typing.List[str]

Run more texts through the embeddings and add to the vectorstore.

adelete

adelete(
    ids: typing.Optional[typing.List[str]] = None, **kwargs: typing.Any
) -> typing.Optional[bool]

Delete by vector ID or other criteria.

Returns
Type Description
Optional[bool] True if deletion is successful, False otherwise, None if not implemented.

afrom_documents

afrom_documents(
    documents: typing.List[langchain_core.documents.base.Document],
    embedding: langchain_core.embeddings.embeddings.Embeddings,
    engine: langchain_google_alloydb_pg.alloydb_engine.AlloyDBEngine,
    table_name: str,
    ids: typing.Optional[typing.List[str]] = None,
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: typing.List[str] = [],
    ignore_metadata_columns: typing.Optional[typing.List[str]] = None,
    id_column: str = "langchain_id",
    metadata_json_column: str = "langchain_metadata",
    **kwargs: typing.Any
) -> langchain_google_alloydb_pg.alloydb_vectorstore.AlloyDBVectorStore

Return VectorStore initialized from documents and embeddings.

afrom_texts

afrom_texts(
    texts: typing.List[str],
    embedding: langchain_core.embeddings.embeddings.Embeddings,
    engine: langchain_google_alloydb_pg.alloydb_engine.AlloyDBEngine,
    table_name: str,
    metadatas: typing.Optional[typing.List[dict]] = None,
    ids: typing.Optional[typing.List[str]] = None,
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: typing.List[str] = [],
    ignore_metadata_columns: typing.Optional[typing.List[str]] = None,
    id_column: str = "langchain_id",
    metadata_json_column: str = "langchain_metadata",
    **kwargs: typing.Any
) -> langchain_google_alloydb_pg.alloydb_vectorstore.AlloyDBVectorStore

Return VectorStore initialized from texts and embeddings.

amax_marginal_relevance_search(
    query: str,
    k: typing.Optional[int] = None,
    fetch_k: typing.Optional[int] = None,
    lambda_mult: typing.Optional[float] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs selected using the maximal marginal relevance.

Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.

amax_marginal_relevance_search_by_vector

amax_marginal_relevance_search_by_vector(
    embedding: typing.List[float],
    k: typing.Optional[int] = None,
    fetch_k: typing.Optional[int] = None,
    lambda_mult: typing.Optional[float] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs selected using the maximal marginal relevance.

asimilarity_search(
    query: str,
    k: typing.Optional[int] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs most similar to query.

asimilarity_search_by_vector

asimilarity_search_by_vector(
    embedding: typing.List[float],
    k: typing.Optional[int] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs most similar to embedding vector.

asimilarity_search_with_score

asimilarity_search_with_score(
    query: str,
    k: typing.Optional[int] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[typing.Tuple[langchain_core.documents.base.Document, float]]

Run similarity search with distance.

create

create(
    engine: langchain_google_alloydb_pg.alloydb_engine.AlloyDBEngine,
    embedding_service: langchain_core.embeddings.embeddings.Embeddings,
    table_name: str,
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: typing.List[str] = [],
    ignore_metadata_columns: typing.Optional[typing.List[str]] = None,
    id_column: str = "langchain_id",
    metadata_json_column: typing.Optional[str] = "langchain_metadata",
    distance_strategy: langchain_google_alloydb_pg.indexes.DistanceStrategy = DistanceStrategy.COSINE_DISTANCE,
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    index_query_options: typing.Optional[
        langchain_google_alloydb_pg.indexes.QueryOptions
    ] = None,
) -> langchain_google_alloydb_pg.alloydb_vectorstore.AlloyDBVectorStore

Constructor for AlloyDBVectorStore.

Parameters
Name Description
engine AlloyDBEngine

Connection pool engine for managing connections to AlloyDB database.

embedding_service Embeddings

Text embedding model to use.

table_name str

Name of the existing table or the table to be created.

content_column str

Column that represent a Document’s page_content. Defaults to "content".

embedding_column str

Column for embedding vectors. The embedding is generated from the document value. Defaults to "embedding".

metadata_columns List[str]

Column(s) that represent a document's metadata.

ignore_metadata_columns List[str]

Column(s) to ignore in pre-existing tables for a document's metadata. Can not be used with metadata_columns. Defaults to None.

id_column str

Column that represents the Document's id. Defaults to "langchain_id".

metadata_json_column str

Column to store metadata as JSON. Defaults to "langchain_metadata".

delete

delete(
    ids: typing.Optional[typing.List[str]] = None, **kwargs: typing.Any
) -> typing.Optional[bool]

Delete by vector ID or other criteria.

Returns
Type Description
Optional[bool] True if deletion is successful, False otherwise, None if not implemented.

from_documents

from_documents(
    documents: typing.List[langchain_core.documents.base.Document],
    embedding: langchain_core.embeddings.embeddings.Embeddings,
    engine: langchain_google_alloydb_pg.alloydb_engine.AlloyDBEngine,
    table_name: str,
    ids: typing.Optional[typing.List[str]] = None,
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: typing.List[str] = [],
    ignore_metadata_columns: typing.Optional[typing.List[str]] = None,
    id_column: str = "langchain_id",
    metadata_json_column: str = "langchain_metadata",
    **kwargs: typing.Any
) -> langchain_google_alloydb_pg.alloydb_vectorstore.AlloyDBVectorStore

Return VectorStore initialized from documents and embeddings.

from_texts

from_texts(
    texts: typing.List[str],
    embedding: langchain_core.embeddings.embeddings.Embeddings,
    engine: langchain_google_alloydb_pg.alloydb_engine.AlloyDBEngine,
    table_name: str,
    metadatas: typing.Optional[typing.List[dict]] = None,
    ids: typing.Optional[typing.List[str]] = None,
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: typing.List[str] = [],
    ignore_metadata_columns: typing.Optional[typing.List[str]] = None,
    id_column: str = "langchain_id",
    metadata_json_column: str = "langchain_metadata",
    **kwargs: typing.Any
) -> langchain_google_alloydb_pg.alloydb_vectorstore.AlloyDBVectorStore

Return VectorStore initialized from texts and embeddings.

max_marginal_relevance_search(
    query: str,
    k: typing.Optional[int] = None,
    fetch_k: typing.Optional[int] = None,
    lambda_mult: typing.Optional[float] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs selected using the maximal marginal relevance.

Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.

max_marginal_relevance_search_by_vector

max_marginal_relevance_search_by_vector(
    embedding: typing.List[float],
    k: typing.Optional[int] = None,
    fetch_k: typing.Optional[int] = None,
    lambda_mult: typing.Optional[float] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs selected using the maximal marginal relevance.

Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.

similarity_search(
    query: str,
    k: typing.Optional[int] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs most similar to query.

similarity_search_by_vector

similarity_search_by_vector(
    embedding: typing.List[float],
    k: typing.Optional[int] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Return docs most similar to embedding vector.

similarity_search_with_score

similarity_search_with_score(
    query: str,
    k: typing.Optional[int] = None,
    filter: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> typing.List[typing.Tuple[langchain_core.documents.base.Document, float]]

Run similarity search with distance.