1. Overview
Patent research is vast and complex. Sifting through countless technical abstracts to find relevant innovations is a daunting task. Traditional keyword-based searches are often inaccurate and time-consuming. Abstracts are lengthy and technical, making it difficult to grasp the core idea quickly. This can lead to researchers missing key patents or wasting time on irrelevant results.
The secret sauce behind this revolution lies in Vector Search. Instead of relying on simple keyword matching, vector search transforms text into numerical representations (embeddings). This allows us to search based on the meaning of the query, not just the specific words used. In the world of literature searches, this is a game-changer. Imagine finding a patent for a "wearable heart rate monitor" even if the exact phrase isn't used in the document.
The Challenge: Modern literature searches are expected to provide instant answers and intelligent recommendations that align with their unique preferences. Traditional search methods often fall short of providing this level of personalization.
The Solution: Our knowledge-driven chat application tackles this challenge head-on. It leverages a rich knowledge base derived from your patent dataset to understand customer intent, respond intelligently, and deliver hyper-relevant results.
What you'll build
As part of this lab (Part 2), you will:
- Build a Vertex AI Agent Builder agent
- Integrate the AlloyDB tool with the agent
Requirements
2. Architecture
Data Flow: Let's take a closer look at how data moves through our system:
Ingestion:
Patents data is loaded into AlloyDB.
Analytics Engine:
We will use AlloyDB as the analytics engine to perform the below:
- Context Extraction: The engine analyzes the data stored within AlloyDB to understand the patents dataset.
- Embedding Creation: Embeddings (mathematical representations of text) are generated for both the user's query and the information stored in AlloyDB.
- Vector Search: The engine performs a similarity search, comparing the query embedding to the embeddings of patent abstracts. This identifies the most relevant "nearest neighbor" to the context that the user is searching for.
Response Generation:
The validated responses are structured into a JSON array and the whole engine is packaged into a serverless Cloud Run Function that is invoked from the Agent Builder.
The above steps are already covered in part 1 of the lab.
We discussed the technical details of creating a knowledge-driven analytics engine that powers our smart patent search assistant. Now, let's explore how we leverage the magic of Agent Builder to bring this engine to life in a conversational interface. Make sure you have the endpoint URL ready before starting part 2. This next step is what we cover in this lab:
Conversational Interaction:
Agent Builder presents the responses to the user in a natural language format, facilitating a back-and-forth dialogue.
3. Before you begin
Create a project
- In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
- Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project .
- You'll use Cloud Shell, a command-line environment running in Google Cloud that comes preloaded with bq. Click Activate Cloud Shell at the top of the Google Cloud console.
- Once connected to Cloud Shell, you check that you're already authenticated and that the project is set to your project ID using the following command:
gcloud auth list
- Run the following command in Cloud Shell to confirm that the gcloud command knows about your project.
gcloud config list project
- If your project is not set, use the following command to set it:
gcloud config set project <YOUR_PROJECT_ID>
- Enable the required APIs. The alternative to the gcloud command is through the console by searching for each product or using this link.
If any API is missed, you can always enable it during the course of the implementation.
Refer documentation for gcloud commands and usage.
Important Note: Also, make sure you have completed PART 1 of the lab in order to complete this.
4. Agent Creation
Introducing Agent Builder
Agent Builder is a powerful, low-code tool that empowers us to create conversational agents quickly and efficiently. It streamlines the process of designing dialog flows, integrating knowledge bases, and connecting to external APIs. In our case, we'll use Agent Builder to seamlessly connect with the Cloud Function endpoint we built in Part 1, enabling our patent search assistant to access our patent knowledge base and respond to user queries intelligently.
Make sure you have the Java Cloud Run Function created in Part 1 returning a JSON ARRAY instead of plain text.
Building the agent
Let's get started with creating this new agent for answering user questions for the apparel products.
- Start by logging into the Agent Builder platform. If it prompts you to activate the API, go ahead and click CONTINUE AND ACTIVATE THE API.
- Click on "CREATE APP" and give your agent a descriptive name (e.g., "Patent Search Assistant").
- Click App Type "Agent".
- . Give your agent a descriptive name like "Patent Search Assistant" and set the region as us-central1
- Enter the details for the agent:
- Change the Agent Name to "Patent Search Agent".
- Add the below "Goal":
You are a professional intelligent patent search agent! Your job is to help the customer find patents matching the context of their search text.
- Save it at this point and leave instructions blank for now.
- Then click Tools from the navigation menu and click CREATE.
Enter Tool Name: Patent Search Tool
Type: OpenAPI
Enter Tool Description:
This tool refers to the dataset in the backend as the context information for product inventory. It takes as input the user's search text summarized by the agent and matches with the most appropriate list of items and returns as an array of items.
Enter Schema — OpenAPI in YAML format:
This is the part where we are using the backend endpoint to power the agent. Copy the below OpenAPI spec and replace the URL placeholder (enclosed in angle brackets) with your Cloud Function endpoint:
openapi: 3.0.0
info:
title: Patent Search API
version: v1
servers:
- url: YOUR_CLOUDFUNCTION_ENDPOINT_URL
paths:
/patent-search:
post:
summary: Search for patents using a text query.
requestBody:
content:
application/json:
schema:
type: object
properties:
search:
type: string
description: The text query to search for patents.
example: A new Natural Language Processing related Machine Learning Model
responses:
'200':
description: Successful search response with a JSON array of matching patents.
content:
application/json:
schema:
type: array
items:
type: object
properties:
result:
type: string
description: Patent title.
'400':
description: Invalid request body.
'500':
description: Internal server error.
Leave other configurations to their default values and click "Save".
- Go back to the Agent at this point because we want to add the "Tool" configuration to the agent's "Instructions". Add the below to the instructions placeholder (Remember, the indents are important in defining the flow):
- Greet the users, then ask how you can help them today.
- Summarize the user's request and ask them to confirm that you understood correctly.
- If necessary, seek clarifying details.
- Use ${TOOL:Patent Search Tool} to help the user with their task.
- Return the response from the ${TOOL:Patent Search Tool} to the user in a well formed string.
- Thank the user for their business and say goodbye.
Make sure the tool "Patent Search Tool" is selected in the "Available Tools" section and then save the agent again.
5. Test the Agent
On the right pane, you should see the Preview Agent section that allows you to test your agent.
As you can see in the screenshot below, I have greeted as a user and started my chat with a request for "Matching patent for any fitness tracker idea":
This is the JSON response:
This is the raw JSON result from the Cloud Function that processes the AlloyDB Similarity Search. That's it! We are all set with the agent now.
6. Deployment and Integration
Once you're satisfied with your agent, you can easily deploy it to various channels using Agent Builder's integrations. You can embed it on your website, integrate it with popular messaging platforms, or even create a dedicated mobile app. We can also use the Agent Builder API directly in our web client applications, which we have covered in this blog.
7. Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this post, follow these steps:
8. Congratulations
Congratulations! By integrating the power of our custom-built analytics engine with the intuitive interface of Agent Builder, we've created an intelligent literature search assistant forward in making literature searches accessible, efficient, and truly meaning-driven. By combining the capabilities of AlloyDB, Vertex AI, and Vector Search, we've taken a giant leap forward in making contextual and vector searches accessible, efficient, truly meaning-driven and agentic!