Skip to main content
This page covers how to use Google Vertex AI Vector Search as a vector store in LangChain.

Overview

Google Vertex AI Vector Search is a fully managed, high-scale, low-latency solution for finding similar vectors. It supports both exact and approximate nearest neighbor (ANN) search using Google’s ScaNN (Scalable Nearest Neighbors) technology. Vertex AI Vector Search is available in two versions:
  • Vector Search 2.0: Uses Collections to store Data Objects containing vectors, metadata, and content together. Provides a unified data model with simpler and quicker operations.
  • Vector Search 1.0: Uses Indexes deployed to Endpoints with separate document storage in Google Cloud Storage or Datastore.
Choose the section below based on which version you’re using: For migrating from Vertex AI Vector Search 1.0 to 2.0, see the Migration Guide.

Installation

Install the LangChain Google Vertex AI integration:

Vector Search 2.0

Vector Search 2.0 uses Collections to store Data Objects. Each Data Object contains vectors, metadata, and content in a unified structure.

Prerequisites

  • Google Cloud project with Vertex AI API and Vector Search APIs enabled
  • Vector Search Collection created (see Creating a Collection)
  • Appropriate IAM permissions (Vertex AI User role or equivalent)

Creating a Collection (V2)

Before using Vector Search 2.0, you need to create a collection. Here’s how to create a collection compatible with LangChain:
Important notes:
  • The vector field must be named "embedding" to match LangChain’s default (or use vector_field_name parameter)
  • Only fields defined in data_schema.properties can be used for filtering in V2
  • Dimensions should match your embedding model (768 for text-embedding-005)

Initialization

Key parameters:
  • collection_id: Your Vector Search Collection ID (required)
  • api_version: Must be set to "v2" (required)
  • project_id: GCP project ID (required)
  • region: GCP region where Collection exists (required)
  • vector_field_name: Name of the vector field in your Collection schema (default: "embedding")

Adding Documents

Adding Texts

Searching

Similarity Search with Scores

Search by Vector

Filtering

Vector Search 2.0 uses dict-based query syntax for filtering Data Objects:
Supported operators:
  • $eq: Equals
  • $ne: Not equals
  • $lt: Less than
  • $lte: Less than or equal
  • $gt: Greater than
  • $gte: Greater than or equal
  • $and: Logical AND
  • $or: Logical OR
  • $not: Logical NOT
See the Vector Search 2.0 query documentation for more details.

Delete Operations

Delete by IDs

Delete by Metadata Filter

Note: Delete by metadata filter has limitations in the current V2 API. The recommended approach is to:
  1. Use similarity_search with your filter to get document IDs
  2. Delete by IDs
Alternatively, if direct metadata deletion is supported in your environment:

Advanced Features

Vector Search 2.0 offers several advanced search capabilities that go beyond traditional dense vector search. Semantic search automatically generates embeddings from your query text using Vertex AI models. Your collection must be configured with vertex_embedding_config in the vector schema.
Task types:
  • RETRIEVAL_QUERY: For search queries (default)
  • RETRIEVAL_DOCUMENT: For document indexing
  • SEMANTIC_SIMILARITY: For semantic similarity tasks
  • CLASSIFICATION: For classification tasks
  • CLUSTERING: For clustering tasks
Text search performs keyword/full-text matching on data fields without using embeddings.
!!! note Text search does not support filters. Use semantic_search() or similarity_search() if you need filtering. Hybrid search combines semantic search (with auto-generated embeddings) and text search (keyword matching) using Reciprocal Rank Fusion (RRF) to produce optimally ranked results.
Weight parameters:
  • Higher semantic_weight: Prioritizes semantic understanding
  • Higher text_weight: Prioritizes exact keyword matches
  • Equal weights (default): Balanced results
Products appearing high in both semantic and text search results will rank highest in the merged results. See the Vector Search 2.0 documentation for more information.

Custom Vector Field Names

If your Collection schema uses a custom field name for vectors:

Additional Resources


Vector Search 1.0

This notebook shows how to use functionality related to the Google Cloud Vertex AI Vector Search vector database.
Google Vertex AI Vector Search, formerly known as 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: LangChain API expects an endpoint and deployed index already created.Index creation time can take upto one hour.
To see how to create an index refer to the section Create Index and deploy it to an Endpoint If you already have an index deployed , skip to Create VectorStore from texts

Create index and deploy it to an endpoint

  • This section demonstrates creating a new index and deploying it to an endpoint

Use VertexAIEmbeddings as the embeddings model

Create an empty index

Note : While creating an index you should specify an “index_update_method” from either a “BATCH_UPDATE” or “STREAM_UPDATE”
A batch index is for when you want to update your index in a batch, with data which has been stored over a set amount of time, like systems which are processed weekly or monthly. A streaming index is when you want index data to be updated as new data is added to your datastore, for instance, if you have a bookstore and want to show new inventory online as soon as possible. Which type you choose is important, since setup and requirements are different.
Refer Official Documentation for more details on configuring indexes

Create an endpoint

Deploy index to the endpoint

Create vector store from texts

NOTE : If you have existing Index and Endpoints, you can load them using below code
Langchainassets.png

Create simple vectorstore ( without filters)

OPTIONAL : You can also create vector and store chunks in a datastore

Create vectorstore with metadata filters

Use vector store as retriever

Use filters with retriever in question answering chains

Read , chunk , vectorise and index PDFs

The langchain-community package is no longer maintained. Examples that import from langchain_community may be outdated or broken. Use with caution.

Hybrid search

Vector Search supports hybrid search, a popular architecture pattern in information retrieval (IR) that combines both semantic search and keyword search (also called token-based search). With hybrid search, developers can take advantage of the best of the two approaches, effectively providing higher search quality. Read the Vertex AI hybrid search documentation to learn more. In order to use hybrid search, we need to fit a sparse embedding vectorizer and handle the embeddings outside of the Vector Search integration. An example of sparse embedding vectorizer is sklearn TfidfVectorizer but other techniques can be used, for instance BM25.