.ipynb
.pdf
MatchingEngine
 Contents 
Create VectorStore from texts
Create Index and deploy it to an Endpoint
Imports, Constants and Configs
Using Tensorflow Universal Sentence Encoder as an Embedder
Inserting a test embedding
Creating Index
Creating Endpoint
Deploy Index
MatchingEngine#
This notebook shows how to use functionality related to the GCP Vertex AI MatchingEngine vector database.
Vertex AI Matching Engine provides the industry’s leading high-scale low latency vector database. These vector databases are commonly referred to as vector similarity-matching or an approximate nearest neighbor (ANN) service.
Note: This module expects an endpoint and deployed index already created as the creation time takes close to one hour. To see how to create an index refer to the section Create Index and deploy it to an Endpoint
Create VectorStore from texts#
from langchain.vectorstores import MatchingEngine
texts = ['The cat sat on', 'the mat.', 'I like to', 'eat pizza for', 'dinner.', 'The sun sets', 'in the west.']
vector_store = MatchingEngine.from_components(
    texts=texts,
    project_id="<my_project_id>",
    region="<my_region>",
    gcs_bucket_uri="<my_gcs_bucket>",
    index_id="<my_matching_engine_index_id>",
    endpoint_id="<my_matching_engine_endpoint_id>"
)
vector_store.add_texts(texts=texts)
vector_store.similarity_search("lunch", k=2)
Create Index and deploy it to an Endpoint#
Imports, Constants and Configs#
# Installing dependencies.
!pip install tensorflow \
            google-cloud-aiplatform \
            tensorflow-hub \
            tensorflow-text 
import os
import json
from google.cloud import aiplatform
import tensorflow_hub as hub
import tensorflow_text
PROJECT_ID = "<my_project_id>"
REGION = "<my_region>"
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/matchingengine.html