Google Vertex AI Search(前称为Enterprise Search on Generative AI App Builder)是Google Cloud提供的Vertex AI机器学习平台的一部分。Vertex AI Search允许组织快速建立由生成式AI驱动的搜索引擎,为客户和员工提供服务。它基于各种Google Search技术,包括语义搜索,通过使用自然语言处理和机器学习技术来推断内容中的关系和用户查询的意图,从而提供比传统关键字搜索技术更相关的结果。
Vertex AI Search在Google Cloud控制台和API中可用,方便企业工作流程集成。
Vertex AI Search利用了Google多年的搜索技术积累。其核心在于语义搜索,通过理解用户的查询意图和内容相关性来提高搜索结果的质量。语义搜索不仅仅依赖于关键词匹配,而是通过分析上下文来提供更准确的答案。
首先,您需要安装langchain-google-community
和google-cloud-discoveryengine
包。
%pip install -qU langchain-google-community google-cloud-discoveryengine
配置前,需要在Google Cloud控制台创建一个搜索引擎并填充数据存储。请参考Vertex AI Search入门指南进行相关设置。
接下来,设置访问凭证:
import sys
if "google.colab" in sys.modules:
from google.colab import auth as google_auth
google_auth.authenticate_user()
以下是如何配置和使用不同类型的数据检索器的示例代码:
from langchain_google_community import VertexAISearchRetriever
PROJECT_ID = ""
LOCATION_ID = ""
DATA_STORE_ID = ""
retriever = VertexAISearchRetriever(
project_id=PROJECT_ID,
location_id=LOCATION_ID,
data_store_id=DATA_STORE_ID,
max_documents=3,
)
query = "What are Alphabet's Other Bets?"
result = retriever.invoke(query)
for doc in result:
print(doc)
retriever = VertexAISearchRetriever(
project_id=PROJECT_ID,
location_id=LOCATION_ID,
data_store_id=DATA_STORE_ID,
max_documents=3,
engine_data_type=1,
)
result = retriever.invoke(query)
for doc in result:
print(doc)
retriever = VertexAISearchRetriever(
project_id=PROJECT_ID,
location_id=LOCATION_ID,
data_store_id=DATA_STORE_ID,
max_documents=3,
max_extractive_answer_count=3,
get_extractive_answers=True,
engine_data_type=2,
)
result = retriever.invoke(query)
for doc in result:
print(doc)
多轮搜索基于生成式AI模型,不同于常规非结构化数据搜索。
from langchain_google_community import VertexAIMultiTurnSearchRetriever
retriever = VertexAIMultiTurnSearchRetriever(
project_id=PROJECT_ID, location_id=LOCATION_ID, data_store_id=DATA_STORE_ID
)
result = retriever.invoke(query)
for doc in result:
print(doc)
Vertex AI Search可以应用于以下场景:
如果遇到问题欢迎在评论区交流。
—END—