Class MySQLVectorStore (0.2.3)

MySQLVectorStore(engine: langchain_google_cloud_sql_mysql.engine.MySQLEngine, 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', k: int = 4, fetch_k: int = 20, lambda_mult: float = 0.5, query_options: langchain_google_cloud_sql_mysql.indexes.QueryOptions = QueryOptions(num_partitions=None, num_neighbors=10, distance_measure=<DistanceMeasure.L2_SQUARED: 'l2_squared'>, search_type=<SearchType.KNN: 'KNN'>))

Constructor for MySQLVectorStore.

Parameters

Name Description
engine MySQLEngine

Connection pool engine for managing connections to Cloud SQL for MySQL database.

embedding_service Embeddings

Text embedding model to use.

table_name str

Name of an existing table or 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".

k int

The number of documents to return as the final result of a similarity search. Defaults to 4.

fetch_k int

The number of documents to initially retrieve from the database during a similarity search. These documents are then re-ranked using MMR to select the final k documents. Defaults to 20.

lambda_mult float

The weight used to balance relevance and diversity in the MMR algorithm. A higher value emphasizes diversity more, while a lower value prioritizes relevance. Defaults to 0.5.

Properties

embeddings

Access the query embedding object if available.

Methods

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.

delete

delete(ids: typing.Optional[typing.List[str]] = None, **kwargs: typing.Any) -> 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_cloud_sql_mysql.engine.MySQLEngine, 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', query_options: langchain_google_cloud_sql_mysql.indexes.QueryOptions = QueryOptions(num_partitions=None, num_neighbors=10, distance_measure=<DistanceMeasure.L2_SQUARED: 'l2_squared'>, search_type=<SearchType.KNN: 'KNN'>), **kwargs: typing.Any) -> langchain_google_cloud_sql_mysql.vectorstore.MySQLVectorStore

Return VectorStore initialized from documents and embeddings.

from_texts

from_texts(texts: typing.List[str], embedding: langchain_core.embeddings.embeddings.Embeddings, engine: langchain_google_cloud_sql_mysql.engine.MySQLEngine, 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', query_options: langchain_google_cloud_sql_mysql.indexes.QueryOptions = QueryOptions(num_partitions=None, num_neighbors=10, distance_measure=<DistanceMeasure.L2_SQUARED: 'l2_squared'>, search_type=<SearchType.KNN: 'KNN'>), **kwargs: typing.Any)

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,
    query_options: typing.Optional[
        langchain_google_cloud_sql_mysql.indexes.QueryOptions
    ] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Performs Maximal Marginal Relevance (MMR) search based on a text query.

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,
    query_options: typing.Optional[
        langchain_google_cloud_sql_mysql.indexes.QueryOptions
    ] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Performs Maximal Marginal Relevance (MMR) search based on a vector embedding.

max_marginal_relevance_search_with_score_by_vector

max_marginal_relevance_search_with_score_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,
    query_options: typing.Optional[
        langchain_google_cloud_sql_mysql.indexes.QueryOptions
    ] = None,
    **kwargs: typing.Any
) -> typing.List[typing.Tuple[langchain_core.documents.base.Document, float]]

Performs Maximal Marginal Relevance (MMR) search based on a vector embedding and returns documents with scores.

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

Searches for similar documents based on a text query.

similarity_search_by_vector

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

Searches for similar documents based on a vector embedding.

similarity_search_with_score

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

Searches for similar documents based on a text query and returns their scores.

similarity_search_with_score_by_vector

similarity_search_with_score_by_vector(
    embedding: typing.List[float],
    k: typing.Optional[int] = None,
    filter: typing.Optional[str] = None,
    query_options: typing.Optional[
        langchain_google_cloud_sql_mysql.indexes.QueryOptions
    ] = None,
    **kwargs: typing.Any
) -> typing.List[typing.Tuple[langchain_core.documents.base.Document, float]]

Searches for similar documents based on a vector embedding and returns their scores.