Class FirestoreVectorStore (0.5.0)

FirestoreVectorStore(
    collection: google.cloud.firestore_v1.collection.CollectionReference | str,
    embedding_service: langchain_core.embeddings.embeddings.Embeddings,
    client: typing.Optional[google.cloud.firestore_v1.client.Client] = None,
    content_field: str = "content",
    metadata_field: str = "metadata",
    embedding_field: str = "embedding",
    distance_strategy: typing.Optional[
        google.cloud.firestore_v1.base_vector_query.DistanceMeasure
    ] = DistanceMeasure.COSINE,
    filters: typing.Optional[google.cloud.firestore_v1.base_query.BaseFilter] = None,
)

Interface for vector store.

Properties

embeddings

Access the query embedding object if available.

Methods

FirestoreVectorStore

FirestoreVectorStore(
    collection: google.cloud.firestore_v1.collection.CollectionReference | str,
    embedding_service: langchain_core.embeddings.embeddings.Embeddings,
    client: typing.Optional[google.cloud.firestore_v1.client.Client] = None,
    content_field: str = "content",
    metadata_field: str = "metadata",
    embedding_field: str = "embedding",
    distance_strategy: typing.Optional[
        google.cloud.firestore_v1.base_vector_query.DistanceMeasure
    ] = DistanceMeasure.COSINE,
    filters: typing.Optional[google.cloud.firestore_v1.base_query.BaseFilter] = None,
)

Constructor for FirestoreVectorStore.

Parameters
Name Description
collection CollectionReference str

The source collection or document

embedding_service Embeddings

The embeddings to use for the vector store.

client Optional[Client]

The Firestore client to use. If not provided,

content_field str

The field name to store the content data.

metadata_field str

The field name to store the metadata.

embedding_field str

The field name to store the text embeddings.

distance_strategy Optional[DistanceMeasure]

The distance strategy to use for

filters Optional[BaseFilter]

The pre-filters to apply to the query. Defaults to None.

_encode_image

_encode_image(uri: str) -> str

Get base64 string from a image URI.

add_images

add_images(
    uris: typing.Iterable[str],
    metadatas: typing.Optional[typing.List[dict]] = None,
    ids: typing.Optional[typing.List[str]] = None,
    store_encodings: bool = False,
    **kwargs: typing.Any
) -> typing.List[str]

Adds image embeddings to Firestore vector store.

Returns
Type Description
List[str] The list of document ids added to the vector store.

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]

Add or update texts in the vector store. If the ids are provided, and a Firestore document with the same id exists, it will be updated. Otherwise, a new Firestore document will be created.

Returns
Type Description
List[str] The list of document ids added to the vector store.

delete

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

Delete documents from the vector store.

from_texts

from_texts(
    texts: typing.List[str],
    embedding: langchain_core.embeddings.embeddings.Embeddings,
    metadatas: typing.Optional[typing.List[dict]] = None,
    ids: typing.Optional[typing.List[str]] = None,
    collection: typing.Optional[
        typing.Union[str, google.cloud.firestore_v1.collection.CollectionReference]
    ] = None,
    **kwargs: typing.Any
) -> langchain_google_firestore.vectorstores.FirestoreVectorStore

Create a FirestoreVectorStore instance and add texts to it.

Returns
Type Description
FirestoreVectorStore The FirestoreVectorStore instance.
max_marginal_relevance_search(
    query: str,
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filters: typing.Optional[google.cloud.firestore_v1.base_query.BaseFilter] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Run max marginal relevance search on the results of Firestore nearest neighbor search.

Exceptions
Type Description
FailedPrecondition If the index is not created.
Returns
Type Description
List[Document] List of documents most similar to the query text.

max_marginal_relevance_search_by_vector

max_marginal_relevance_search_by_vector(
    embedding: typing.List[float],
    k: int = 4,
    fetch_k: int = 20,
    lambda_mult: float = 0.5,
    filters: typing.Optional[google.cloud.firestore_v1.base_query.BaseFilter] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Run max marginal relevance search on the results of Firestore nearest neighbor search using a vector. This method will throw if the index is not created, in which case you will be prompted to create the index.

Exceptions
Type Description
FailedPrecondition If the index is not created.
Returns
Type Description
List[Document] List of documents most similar to the query vector.
similarity_search(
    query: str,
    k: int = 4,
    filters: typing.Optional[google.cloud.firestore_v1.base_query.BaseFilter] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Run similarity search with Firestore.

Exceptions
Type Description
FailedPrecondition If the index is not created.
Returns
Type Description
List[Document] List of documents most similar to the query text.

similarity_search_by_vector

similarity_search_by_vector(
    embedding: typing.List[float],
    k: int = 4,
    filters: typing.Optional[google.cloud.firestore_v1.base_query.BaseFilter] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Run similarity search with Firestore using a vector.

Exceptions
Type Description
FailedPrecondition If the index is not created.
Returns
Type Description
List[Document] List of documents most similar to the query vector.

similarity_search_image

similarity_search_image(
    image_uri: str,
    k: int = 4,
    filters: typing.Optional[google.cloud.firestore_v1.base_query.BaseFilter] = None,
    **kwargs: typing.Any
) -> typing.List[langchain_core.documents.base.Document]

Run image similarity search with Firestore.

Exceptions
Type Description
FailedPrecondition If the index is not created.
Returns
Type Description
List[Document] List of documents most similar to the image.