Esta página apresenta a pesquisa com respostas e acompanhamentos para a Vertex AI para Pesquisa e
mostra como implementá-lo em apps de pesquisa genérica usando chamadas de método.
Observação : os recursos de resposta e acompanhamento não podem ser aplicados a repositórios de dados de mídia ou de saúde.
A pesquisa com resposta e acompanhamentos é baseada no método de resposta. O método de resposta
substitui os recursos de resumo do método search mais antigo
e todos os recursos do método converse descontinuado.
O método de resposta também tem alguns outros recursos importantes, como
e capacidade de lidar com consultas complexas.
Termo-chave :nesta página, o termo resposta se refere a uma resposta gerada por IA que
se baseia nos resultados de uma consulta. Essencialmente, é igual ao
resumo , que pode ser gerado pelo método de pesquisa.
Recursos do método "answer"
As principais características do método de resposta são as seguintes:
Capacidade de gerar respostas para consultas complexas. Por exemplo, a resposta
pode dividir consultas compostas, como as seguintes,
em várias consultas menores para retornar melhores resultados que são usados para
potencializar respostas melhores:
"Qual é a receita do Google Cloud e do Google Ads em 2024?"
"Após quantos anos desde sua fundação, o Google alcançou US$ 1 bilhão
receita?"
A capacidade de combinar pesquisa e geração de respostas em vários turnos
conversa chamando o método de resposta em cada turno.
A capacidade de parear com o método de pesquisa para reduzir a latência da pesquisa. É
possível chamar o método de pesquisa e o método de resposta separadamente e renderizar
os resultados da pesquisa e as respostas em diferentes iframes em momentos diferentes. Isso
significa que você pode mostrar aos usuários os resultados da pesquisa (os 10 links azuis) em
milissegundos. Não é necessário esperar que as respostas sejam geradas para mostrar os resultados da pesquisa.
Os recursos de resposta e acompanhamento podem ser divididos em três fases da consulta,
pesquisar e responder:
Quando usar a resposta e a pesquisa
A Vertex AI para Pesquisa tem dois métodos usados para consultar apps. Eles têm recursos diferentes, mas
sobrepostos.
Use o método answer quando:
Você quer uma resposta (ou resumo) gerada por IA dos resultados da pesquisa.
Você quer a pesquisa com várias interações, ou seja, pesquisas que mantenham o contexto para permitir
perguntas de acompanhamento.
Use o método search quando:
Você só precisa dos resultados da pesquisa, não de uma resposta gerada.
Você quer que sejam retornados mais de dez resultados de pesquisa ("links azuis").
Você tem o seguinte:
Dados de mídia ou de saúde
Seus próprios embeddings
Controles de redirecionamento ou sinônimos
Atributos
Códigos de país do usuário
Use os métodos de resposta e de pesquisa juntos quando:
Você quer retornar mais de dez resultados de pesquisa e quer uma resposta
gerada.
Você está com problemas de latência e quer retornar e mostrar os resultados da pesquisa rapidamente
antes que a resposta gerada seja retornada.
Recursos da fase de consulta
O recurso de resposta e acompanhamentos oferece suporte ao processamento de consultas de linguagem natural.
Esta seção descreve e ilustra as várias opções de reformulação e classificação de consultas.
Reformulação da consulta
A reformulação de consultas fica ativada por padrão. Este recurso escolhe a melhor maneira de reformular
consultas automaticamente para melhorar os resultados da pesquisa. Esse recurso também pode lidar
consultas que não exigem reformulação.
Divida consultas complexas em várias e execute consultas síncronas
subconsulta.
Por exemplo, uma consulta complexa é dividida em quatro consultas menores e
mais simples.
Entrada do usuário
Subconsultas criadas a partir de uma consulta complexa
Quais trabalhos e hobbies Andie Ram e Arnaud
Clément têm em comum?
Ocupação de Andie Ram
Profissão de Arnaud Clément
Hobby de Andie Ram
Arnaud Clément
Sintetize consultas de várias etapas para que as perguntas de acompanhamento sejam sensíveis ao contexto
e tenham estado.
Por exemplo, as consultas sintetizadas a partir da entrada do usuário em cada turno podem ser
semelhantes a esta:
Entrada do usuário
Consulta sintetizada
1a rodada: laptops para a escola
laptops para a escola
Turno 2: não é um Mac
laptops para escola, não mac
Turn 3: tela maior e também preciso de um teclado sem fio e
-rato
laptops com tela maior para escola não Mac com teclado sem fio e
-rato
Turn 4: e uma mochila para ele
laptops de tela maior para a escola, não Mac, com teclado e
mouse sem fio e uma mochila para ele
Simplifique consultas longas para melhorar a recuperação.
Por exemplo, uma consulta longa é encurtada para uma consulta simples.
Entrada do usuário
Consulta simplificada
Estou tentando descobrir por que \"Adicionar ao carrinho\"
no nosso site não está funcionando corretamente. Parece que, quando um
usuário clica no botão, o item não é adicionado ao carrinho e ele
recebe uma mensagem de erro. Verifiquei o código, e ele parece estar
correto. Não sei qual é o problema. Você pode me ajudar
a resolver esse problema?
O botão "Adicionar ao carrinho" não funciona no site.
Realizar o raciocínio em várias etapas
Termos-chave : etapas (também chamadas de saltos ) são
usadas para responder a perguntas complexas. A pergunta é dividida em
várias etapas de recuperação e inferência de informações.
O raciocínio em várias etapas é baseado no paradigma ReAct (reason + act), que
permite que os LLMs resolvam tarefas complexas usando o raciocínio de linguagem natural.
Por padrão, o número máximo de etapas é cinco.
Exemplo:
Entrada do usuário
Duas etapas para gerar a resposta
Quantos anos desde sua fundação, o Google alcançou 1
de bilhões de dólares americanos?
Etapa 1 :
[Pensamento]: preciso saber quando o Google foi fundado para consultar a receita desde então.
[Ação] Pesquisa: quando o Google foi fundado?[Observe os resultados da pesquisa]: "1998"
Etapa 2:
[Pensamento]: Agora preciso da receita anual do Google
desde 1998, e saber quando ultrapassou a marca de 1 bilhão pela primeira vez.
[Ato] Pesquisa: receita do Google desde 1998
[Observe os resultados da pesquisa] Receita do Google em 1998, receita do Google em 1999...
[Resposta]: O Google alcançou mais de US$ 1 bilhão
em receita em 2003 [1], cinco anos após sua fundação em 1998[2].
Classificação de consultas
As opções de classificação de consulta servem para identificar consultas adversas e consultas que não buscam respostas. Por padrão, as opções de classificação de consulta estão desativadas.
Para mais informações sobre consultas de busca de adversários e sem resposta, consulte Ignorar consultas
consultas e Ignorar a busca que não seja de resumo
consultas .
Recursos da fase de pesquisa
Para pesquisas, o método de resposta tem as mesmas opções que o método de pesquisa. Exemplo:
Recursos da fase de resposta
Durante a fase de resposta, quando as respostas são geradas a partir dos resultados da pesquisa, você
pode ativar os mesmos recursos do método de pesquisa. Exemplo:
Antes de começar
Dependendo do tipo de app, conclua os seguintes requisitos:
Se você tiver um app de pesquisa estruturada ou não estruturada, verifique se a opção
Recursos avançados do LLM está ativada.
Se você tiver um app de pesquisa em sites, verifique se as seguintes opções estão ativadas:
Se você tem um aplicativo de pesquisa mista (ou seja, um aplicativo conectado a mais
de um repositório de dados), entre em contato com a Equipe de Contas do Google e peça para ser adicionado a
a lista de permissões da API de resposta com pesquisa combinada.
Pesquisa e resposta (básico)
O comando a seguir mostra como chamar o método answer e
retornam uma resposta gerada e uma lista de resultados de pesquisa, com links para o
de dados.
Esse comando mostra apenas a entrada necessária. As opções são deixadas nos
padrão.
REST
Para pesquisar e receber resultados com uma resposta gerada, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém o
pergunta ou consulta de pesquisa. Por exemplo, "Compare o BigQuery e o Spanner
bancos de dados?".
Exemplo de comando e resultado parcial
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{"query": { "text": "Which database is faster, bigquery or spanner?"}}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "The provided sources do not directly compare the speed of BigQuery and Spanner. However, they do highlight the performance capabilities of each database. BigQuery is described as having strong query performance, particularly for short and complex queries. It also offers a serverless architecture that provides consistent performance regardless of query complexity. Spanner is described as having high performance at virtually unlimited scale, with single-digit millisecond latency for strongly-consistent reads and writes. It also offers a five-nines availability SLA. Ultimately, the best database for a particular use case will depend on the specific requirements of the application. \n",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": " What is the performance of BigQuery? "
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/9ab3ef91bcfde1fcd091efe9df7c699c",
"uri": "https://cloud.google.com/bigquery/docs/best-practices-performance-overview",
"title": "Introduction to optimizing query performance | BigQuery | Google Cloud",
"snippetInfo": [
{
"snippet": "After a query begins execution, \u003cb\u003eBigQuery\u003c/b\u003e calculates how many slots each query stage uses based on the stage size and complexity and the number of slots ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/4e545c5cb69b06b251265114d9099cb4",
"uri": "https://cloud.google.com/bigquery/docs/query-insights",
"title": "Get query performance insights | BigQuery | Google Cloud",
"snippetInfo": [
{
"snippet": "This document describes how to use the query execution graph to diagnose query \u003cb\u003eperformance\u003c/b\u003e issues, and to see query \u003cb\u003eperformance\u003c/b\u003e insights. \u003cb\u003eBigQuery\u003c/b\u003e offers ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/d34672d877eefe596f9c7d1a3d7076b1",
"uri": "https://cloud.google.com/bigquery/docs/best-practices-performance-compute",
"title": "Optimize query computation | BigQuery | Google Cloud",
"snippetInfo": [
{
"snippet": "After addressing the query \u003cb\u003eperformance\u003c/b\u003e insights, you can further optimize your query by performing the following tasks: Reduce data that is to be processed ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/75ce2f05833683e60ddc21a11ce0466f",
"uri": "https://cloud.google.com/blog/products/data-analytics/troubleshoot-and-optimize-your-bigquery-analytics-queries-with-query-execution-graph/",
"title": "Troubleshoot and optimize your BigQuery analytics queries with query execution graph | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "Since query \u003cb\u003eperformance\u003c/b\u003e is multi-faceted, \u003cb\u003eperformance\u003c/b\u003e insights might only provide a partial picture of the overall query \u003cb\u003eperformance\u003c/b\u003e. Execution graph. When ...",
"snippetStatus": "SUCCESS"
}
]
}
]
}
},
{
"searchAction": {
"query": " What is the performance of Spanner? "
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/f3d036b60379873acf7c73081c5e5b5c",
"uri": "https://cloud.google.com/spanner/docs/performance",
"title": "Performance overview | Spanner | Google Cloud",
"snippetInfo": [
{
"snippet": "These \u003cb\u003eperformance\u003c/b\u003e improvements should result in higher throughput and better latency in \u003cb\u003eSpanner\u003c/b\u003e nodes in both regional and multi-region instance configurations.",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/422496248ade354c73b4c906b8eb9b5f",
"uri": "https://cloud.google.com/blog/products/databases/announcing-cloud-spanner-price-performance-updates",
"title": "Announcing Cloud Spanner price-performance updates | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "Alongside lower costs, Cloud \u003cb\u003eSpanner\u003c/b\u003e provides single-digit ms latencies and strong consistency across multiple availability zones in the same region.",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/53c2a1a6990480ba4aa05cc6b4404562",
"uri": "https://cloud.google.com/blog/topics/developers-practitioners/understanding-cloud-spanner-performance-metrics-scale-key-visualizer",
"title": "Understanding Cloud Spanner performance metrics at scale with Key Visualizer | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "Designed for \u003cb\u003eperformance\u003c/b\u003e tuning and instance sizing, you can use Key Visualizer today in the web-based Cloud Console for all \u003cb\u003eSpanner\u003c/b\u003e databases at no additional ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/a6501ecd5d6391e3ade49097bab0ad3a",
"uri": "https://cloud.google.com/blog/products/databases/a-technical-overview-of-cloud-spanners-query-optimizer",
"title": "A technical overview of Cloud Spanner's query optimizer | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "... performance. Typically, a join will ... Google is continuously improving out-of-the-box \u003cb\u003eperformance of Spanner\u003c/b\u003e and reducing the need for manual tuning.",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
]
},
"answerQueryToken": "NMwKDAj1_d62BhC72_X_AhIkNjZkN2I4YWEtMDAwMC0yYTdiLWIxMmMtMDg5ZTA4MjhlNzY0"
}
Neste exemplo, a consulta é decomposta em partes: "Qual é a
o desempenho do Spanner?" e "Qual é o desempenho do BigQuery?"
Comandos da fase de consulta
Esta seção mostra como especificar opções para a fase de consulta da
answer .
Pesquisar e responder (reformulação desativada)
O comando a seguir mostra como chamar o método answer e
retorna uma resposta gerada e uma lista de resultados de pesquisa. A resposta poderia ser
diferente da resposta anterior, porque a opção de reformulação está desativada.
REST
Para pesquisar e receber resultados com uma resposta gerada sem aplicar a reformulação
da consulta, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"queryUnderstandingSpec": {
"queryRephraserSpec": {
"disable": true
}
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa.
QUERY
: uma string de texto livre que contém o
pergunta ou consulta de pesquisa. Por exemplo, "Compare o BigQuery e o Spanner
bancos de dados?".
Exemplo de comando e resultado parcial
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{
"query": { "text": "Which database is faster, bigquery or spanner?"},
"queryUnderstandingSpec": { "queryRephraserSpec": { "disable": true } }
}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "The sources provided do not directly compare the speed of BigQuery and Spanner. They do mention that Spanner is optimized for transactional workloads and BigQuery is optimized for analytical workloads. Spanner is a fully managed relational database that provides seamless replication across regions in Google Cloud. BigQuery is a serverless, highly scalable, and cost-effective multi-cloud data warehouse. Spanner is designed to scale horizontally across multiple regions and continents. BigQuery is designed for business agility. \n",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "Which database is faster, bigquery or spanner? "
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/ecc0e7547253f4ca3ff3328ce89995af",
"uri": "https://cloud.google.com/blog/topics/developers-practitioners/how-spanner-and-bigquery-work-together-handle-transactional-and-analytical-workloads",
"title": "How Spanner and BigQuery work together to handle transactional and analytical workloads | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "A federated \u003cb\u003equery\u003c/b\u003e might not be as \u003cb\u003efast\u003c/b\u003e as querying local \u003cb\u003eBigQuery tables\u003c/b\u003e. There may be higher latency because of the small wait time for the source \u003cb\u003edatabase\u003c/b\u003e to ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/d7e238f73608a860e00b752ef80e2941",
"uri": "https://cloud.google.com/blog/products/databases/cloud-spanner-gets-stronger-with-bigquery-federated-queries",
"title": "Cloud Spanner gets stronger with BigQuery-federated queries | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "... \u003cb\u003equick\u003c/b\u003e lookup on \u003cb\u003edata\u003c/b\u003e that's in \u003cb\u003eSpanner\u003c/b\u003e -- you can ... Set up an external \u003cb\u003edata\u003c/b\u003e source for the \u003cb\u003eSpanner\u003c/b\u003e shopping \u003cb\u003edatabase\u003c/b\u003e in \u003cb\u003eBigQuery\u003c/b\u003e. ... The \u003cb\u003equery\u003c/b\u003e is executed in ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/f3d036b60379873acf7c73081c5e5b5c",
"uri": "https://cloud.google.com/spanner/docs/performance",
"title": "Performance overview | Spanner | Google Cloud",
"snippetInfo": [
{
"snippet": "The information on this page applies to both GoogleSQL and PostgreSQL \u003cb\u003edatabases\u003c/b\u003e. Note: We are in the process of rolling out \u003cb\u003eperformance\u003c/b\u003e and storage changes that ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/47b09cb5ad5e3ab3b1eb93d99ecb0896",
"uri": "https://cloud.google.com/blog/products/databases/rewe-uses-cloud-spanner-to-optimize-for-speed-and-performance",
"title": "REWE uses Cloud Spanner to optimize for speed and performance | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "As a fully managed relational \u003cb\u003edatabase\u003c/b\u003e, \u003cb\u003eSpanner\u003c/b\u003e provides unlimited scale, strong consistency, and up to 99.999% availability. By choosing this approach to ...",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
]
},
"answerQueryToken": "M8gKCwjp_t62BhC7wOFMEiQ2NmQ3YjhhZS0wMDAwLTJhN2ItYjEyYy0wODllMDgyOGU3NjQ"
}
Pesquisar e responder (especificar o número máximo de etapas)
O comando a seguir mostra como chamar o método answer e
retorna uma resposta gerada e uma lista de resultados de pesquisa. A resposta é:
diferente das respostas anteriores porque o número de etapas de reformulação
aumentou.
REST
Para pesquisar e receber resultados com uma resposta gerada que permite até cinco etapas de reformulação, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"queryUnderstandingSpec": {
"queryRephraserSpec": {
"maxRephraseSteps": MAX_REPHRASE
}
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa. Por exemplo, "Comparar os bancos de dados do BigQuery e do Spanner?".
MAX_REPHRASE
: o número máximo de reformulações
etapas. O valor máximo permitido é 5
.
Se não for definido ou se for definido como menor que 1
, o valor será o padrão.
1
:
Exemplo de comando
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{
"query": { "text": "How much longer does it take to train a recommendations model than a search model"},
"queryUnderstandingSpec": {
"queryRephraserSpec": {
"maxRephraseSteps": 5
}
}
}'
Pesquisar e responder com a classificação de consulta
O comando a seguir mostra como chamar o método answer para
saber se uma consulta é adversarial, não busca uma resposta ou nenhuma das duas.
A resposta inclui o tipo de classificação da consulta, mas a resposta em si não é afetada pela classificação.
Se você quiser mudar o comportamento de resposta de acordo com o tipo de consulta, faça isso
na fase de resposta. Consulte Ignorar consultas
adversárias e Ignorar consultas que não buscam
resumo .
REST
Para determinar se uma consulta é de adversários ou não de respostas, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"queryUnderstandingSpec": {
"queryClassificationSpec": {
"types": ["QUERY_CLASSIFICATION_TYPE "]
}
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém o
pergunta ou consulta de pesquisa. Por exemplo, "olá".
QUERY_CLASSIFICATION_TYPE
: os tipos de consulta
que você quer identificar: ADVERSARIAL_QUERY
,
NON_ANSWER_SEEKING_QUERY
ou ambos.
Exemplo de comando e resultado parcial
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{
"query": {
"text": "Hello!"},
"queryUnderstandingSpec": {
"queryClassificationSpec": {
"types": ["ADVERSARIAL_QUERY", "NON_ANSWER_SEEKING_QUERY"]
}
}
}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "A user reported that their Google Voice account was randomly sending \"Hello!\" replies to incoming texts. The user was frustrated because they did not want to send these replies and found the behavior random. The user was unable to find any linked accounts, Google extensions, or other settings that could be causing the issue. The user confirmed that Google Voice does not have auto-reply functions. The user was seeking help to stop the automatic replies. \n",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "Hello!"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/69e92e5b1de5b1e583fbe95f94dd4cbf",
"uri": "https://support.google.com/voice/thread/152245405/google-voice-is-randomly-automatically-sending-hello-replies-to-incoming-texts?hl=en",
"title": "Google voice is randomly/automatically sending \"Hello!\" replies to incoming texts",
"snippetInfo": [
{
"snippet": "There IS a new "Smart reply" feature on the Android or iOS client apps, but you'd have to a) receive a SMS/MMS, b) open it up, c) look at the three suggested ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/44fb313bcc09877e7239f3810ddb132b",
"uri": "https://support.google.com/mail/thread/58174131/gmail-sends-random-email-saying-hello-to-my-emails-without-me-touching-it?hl=en",
"title": "Gmail sends random email saying \"Hello!!\" to my emails without me touching it",
"snippetInfo": [
{
"snippet": "Gmail sends random email saying "\u003cb\u003eHello\u003c/b\u003e!!" to my emails without me touching it. Whenever I email somebody and they reply, a random email from my Gmail is sent to ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/16d65e2af7fa854d1a00995525646dc3",
"uri": "https://support.google.com/voice/thread/112990484/google-voice-sending-hello-in-response-to-text-messages?hl=en",
"title": "Google Voice sending \"Hello,\" in response to text messages",
"snippetInfo": [
{
"snippet": "When I receive text messages, a reply is instantly sent out reading "\u003cb\u003eHello\u003c/b\u003e," and I cannot figure out how this is happening. I have no linked accounts, ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/a828eb8f442f1dfbdda06dbeb52841b0",
"uri": "https://support.google.com/a/thread/161821861/hello-hello-the-lost-phone?hl=en",
"title": "Hello.Hello the lost phone - Google Workspace Admin Community",
"snippetInfo": [
{
"snippet": "\u003cb\u003eHello\u003c/b\u003e the lost phone. My wife lost her phone but she cannot remember her emails pasward to help track .",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
],
"queryUnderstandingInfo": {
"queryClassificationInfo": [
{
"type": "ADVERSARIAL_QUERY"
},
{
"type": "NON_ANSWER_SEEKING_QUERY",
"positive": true
}
]
}
},
"answerQueryToken": "NMwKDAjVloK3BhCdt8u9AhIkNjZkYmFhNWItMDAwMC0yZTBkLTg0ZDAtMDg5ZTA4MmRjYjg0"
}
Neste exemplo, a consulta "hello" não são adversários, mas são classificados como
que não estão em busca de respostas.
Comandos da fase de pesquisa: pesquise e responda com opções de resultados da pesquisa
Esta seção mostra como especificar opções para a parte da fase de pesquisa do
chamada do método answer , opções como a definição do número máximo
de documentos retornados, otimização e filtragem, e como obter uma resposta quando
você fornece seus próprios resultados de pesquisa.
O comando a seguir mostra como chamar o método answer e
especificar várias opções de como o resultado da pesquisa é retornado. (A pesquisa
resultados são independentes da resposta.)
REST
Para definir várias opções relacionadas a quais e como os resultados da pesquisa são retornados, faça
o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"searchSpec": {
"searchParams": {
"maxReturnResults": MAX_RETURN_RESULTS ,
"filter": "FILTER ",
"boostSpec": BOOST_SPEC ,
"orderBy": "ORDER_BY ",
"searchResultMode": SEARCH_RESULT_MODE
}
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa. Por exemplo, "Comparar os bancos de dados do BigQuery e do Spanner?"
MAX_RETURN_RESULTS
: o número de pesquisas
resultados a serem retornados. O valor padrão é 10.
FILTER
: o filtro especifica quais documentos
são consultados. Se os metadados de um documento atenderem à especificação do filtro,
o documento será consultado. Para mais informações, incluindo a sintaxe de filtro, consulte Filtrar a pesquisa genérica para dados estruturados ou não estruturados .
BOOST_SPEC
: a especificação de otimização permite que você
otimizar determinados documentos nos resultados da pesquisa, o que pode afetar a resposta.
Para mais informações, incluindo a sintaxe da especificação de otimização, consulte
Melhore os resultados da pesquisa .
ORDER_BY
: a ordem em que os documentos são
retornados. Os documentos podem ser ordenados por um campo em um
objeto
Document . A expressão orderBy
diferencia maiúsculas de minúsculas.
Se esse campo não for reconhecido, um INVALID_ARGUMENT
será
retornado.
SEARCH_RESULT_MODE
: especifica a pesquisa
modo de resultado: DOCUMENTS
ou CHUNKS
. Para mais
informações, consulte
Analisar e
em partes de documentos e ContentSearchSpec .
Esse campo está disponível apenas na versão v1alpha da API.
Exemplo de comando e resultado
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{
"query": {
"text": "Does spanner database have an API?"},
"searchSpec": {
"searchParams": { "maxReturnResults": 3 }
}
}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "Spanner database has an API that provides programmatic access to the database. The API is available through client libraries, RPC, and REST. The client libraries allow you to interact with Spanner in your preferred language. The RPC API and REST API provide programmatic access to Spanner. The Cloud Spanner API is a managed, mission-critical, globally consistent and scalable relational database service. \n",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "Does spanner database have an API?"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/d135b46c4a44d0cc6b652538c1887f4d",
"uri": "https://cloud.google.com/spanner/docs/apis",
"title": "APIs & reference | Spanner | Google Cloud",
"snippetInfo": [
{
"snippet": "The client libraries, the RPC \u003cb\u003eAPI\u003c/b\u003e, and the REST \u003cb\u003eAPI\u003c/b\u003e provide programmatic access to \u003cb\u003eSpanner\u003c/b\u003e. \u003cb\u003eSpanner\u003c/b\u003e client libraries. \u003cb\u003eGet\u003c/b\u003e started with \u003cb\u003eSpanner\u003c/b\u003e in your language ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/7a744d43e61ccd33539de74d5c1f6313",
"uri": "https://cloud.google.com/spanner/docs/reference/rest",
"title": "Cloud Spanner API",
"snippetInfo": [
{
"snippet": "Returns permissions that the caller \u003cb\u003ehas\u003c/b\u003e on the specified \u003cb\u003edatabase\u003c/b\u003e or backup resource. updateDdl, PATCH /v1/{\u003cb\u003edatabase\u003c/b\u003e=projects/*/instances/*/\u003cb\u003edatabases\u003c/b\u003e/*}/ddl",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/70834ebf4b72b6dc69e06c44ee80f90b",
"uri": "https://cloud.google.com/spanner/docs/reference/rpc",
"title": "Cloud Spanner API",
"snippetInfo": [
{
"snippet": "ChangeQuorum \u003cb\u003eis\u003c/b\u003e strictly restricted to \u003cb\u003edatabases\u003c/b\u003e ... Returns the schema of a Cloud \u003cb\u003eSpanner database\u003c/b\u003e ... Returns permissions that the caller \u003cb\u003ehas\u003c/b\u003e on the specified ...",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
]
},
"answerQueryToken": "NMwKDAj2l4K3BhCqiv66ARIkNjZkYmFhNmMtMDAwMC0yZTBkLTg0ZDAtMDg5ZTA4MmRjYjg0"
}
Neste exemplo, o número de documentos retornados é limitado a três.
Comandos da fase de resposta
Esta seção mostra como especificar opções específicas de respostas para os
answer .
Ignorar consultas de adversários e consultas que não buscam respostas
O comando a seguir mostra como evitar responder a consultas de adversários e
consultas que não buscam respostas ao chamar o método answer .
REST
Para pular as consultas que são hostis ou não buscam respostas, faça o
seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"answerGenerationSpec": {
"ignoreAdversarialQuery": true,
"ignoreNonAnswerSeekingQuery": true
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa.
Exemplo de comando e resultado parcial
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{
"query": { "text": "Hello"},
"answerGenerationSpec": {
"ignoreAdversarialQuery": true ,
"ignoreNonAnswerSeekingQuery": true }
}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "A summary could not be generated for your search query. Here are some search results. ",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "Hello"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/69e92e5b1de5b1e583fbe95f94dd4cbf",
"uri": "https://support.google.com/voice/thread/152245405/google-voice-is-randomly-automatically-sending-hello-replies-to-incoming-texts?hl=en",
"title": "Google voice is randomly/automatically sending \"Hello!\" replies to incoming texts",
"snippetInfo": [
{
"snippet": "There IS a new "Smart reply" feature on the Android or iOS client apps, but you'd have to a) receive a SMS/MMS, b) open it up, c) look at the three suggested ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/16d65e2af7fa854d1a00995525646dc3",
"uri": "https://support.google.com/voice/thread/112990484/google-voice-sending-hello-in-response-to-text-messages?hl=en",
"title": "Google Voice sending \"Hello,\" in response to text messages",
"snippetInfo": [
{
"snippet": "When I receive text messages, a reply is instantly sent out reading "\u003cb\u003eHello\u003c/b\u003e," and I cannot figure out how this is happening. I have no linked accounts, ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/b3bdde4957f588a1458c533269626d09",
"uri": "https://support.google.com/voice/thread/4307458/lately-an-automatic-text-response-saying-hello-is-going-out-how-do-i-stop-this?hl=en",
"title": "Lately an automatic text response saying, \"Hello\" is going out. How do I stop this? - Google Voice Community",
"snippetInfo": [
{
"snippet": "You need to find out what app is causing it and deactivate or delete it. Last edited Apr 16, 2019.",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/a828eb8f442f1dfbdda06dbeb52841b0",
"uri": "https://support.google.com/a/thread/161821861/hello-hello-the-lost-phone?hl=en",
"title": "Hello.Hello the lost phone - Google Workspace Admin Community",
"snippetInfo": [
{
"snippet": "\u003cb\u003eHello\u003c/b\u003e the lost phone. My wife lost her phone but she cannot remember her emails pasward to help track .",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
],
"answerSkippedReasons": [
"NON_ANSWER_SEEKING_QUERY_IGNORED"
]
},
"answerQueryToken": "NMwKDAjFgN-2BhDlsKaZARIkNjZkN2I0NmItMDAwMC0yZmQ5LTkwMDktZjQwMzA0M2E5YTg4"
}
Neste exemplo, a consulta é determinada como não buscando respostas e, portanto,
uma resposta é gerada.
Mostrar apenas respostas relevantes
A Vertex AI para Pesquisa pode avaliar a relevância dos resultados
consulta. Se nenhum resultado for considerado relevante o suficiente, em vez
de gerar uma resposta a partir de resultados pouco relevantes ou minimamente relevantes, poderá
optar por retornar uma resposta substituta: "We do not have a summary for your query.
"
O comando a seguir mostra como retornar a resposta alternativa no caso de
resultados irrelevantes ao chamar o método answer .
REST
Para retornar uma resposta substituta se nenhum resultado relevante for encontrado, faça o
seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"answerGenerationSpec": {
"ignoreLowRelevantContent": true
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa.
Exemplo de comando e resultado
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{"query": { "text": "foobar"}, "answerGenerationSpec": {
"ignoreLowRelevantContent": true
} }'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "We do not have a summary for your query.",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "foobar"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/719b79786f0c143717c569eade5305d9",
"uri": "https://support.google.com/websearch/thread/261714267/google-foobar-bug-console-disappeared?hl=en",
"title": "Google Foobar Bug - Console Disappeared",
"snippetInfo": [
{
"snippet": "Google \u003cb\u003eFoobar\u003c/b\u003e Bug - Console Disappeared. After I logged in today the top bar says "The \u003cb\u003eFoobar\u003c/b\u003e Challenge will be turned down on 1 April 2024. If you run out of ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/932369826585ff45f6ab3eba01ba6933",
"uri": "https://support.google.com/websearch/thread/95251114/unable-to-contact-foobar-recruiter?hl=en",
"title": "Unable to contact Foobar Recruiter - Google Search Community",
"snippetInfo": [
{
"snippet": "Access is by invitation only so you will need to have the proper credentials to login. You can always reach out using the contact us button, but there is no ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/fb736a30ff90d058be755f0a04a522a8",
"uri": "https://support.google.com/websearch/thread/121151780/foobar-challenge-appeared-to-me-then-disappeared?hl=en",
"title": "Foobar challenge appeared to me then disappeared - Google Search Community",
"snippetInfo": [
{
"snippet": "Hi. I got the \u003cb\u003efoobar\u003c/b\u003e challenge some months ago. But then it disappeared immediately, maybe by misclick (though I don't think I misclicked).",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/f56f2656b0d02b839509d0e67e60c1c9",
"uri": "https://support.google.com/chrome/thread/159931759/cannot-access-google-foobar-challenge?hl=en",
"title": "Cannot Access Google FooBar Challenge",
"snippetInfo": [
{
"snippet": "I knew I wouldn't have time for it today, so I just kept the tab in the background. Tonight, I went to go close all my tabs, but the page had changed. It said " ...",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
],
"answerSkippedReasons": [
"NO_RELEVANT_CONTENT"
]
},
"answerQueryToken": "M8gKCwiokvy2BhDtv8EDEiQ2NmQ5NDQxZC0wMDAwLTIxMGQtOWU2Yi1mNDAzMDQ1ZGJkMzA"
}
Neste exemplo, os resultados foram determinados como não suficientemente relevantes
para a consulta. Portanto, a resposta alternativa foi retornada em vez de uma resposta
gerada e resultados.
Especificar o modelo de resposta
O comando a seguir mostra como alterar a versão do modelo usada para gerar
respostas
Para informações sobre os modelos compatíveis, consulte Versões e ciclo de vida do modelo de geração de respostas .
REST
Para gerar uma resposta usando um modelo diferente do padrão, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"answerGenerationSpec": {
"modelSpec": {
"modelVersion": "MODEL_VERSION ",
}
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa.
MODEL_VERSION
: a versão do modelo que você quer usar para gerar a
resposta. Para mais
informações, consulte Versões e ciclo de vida do
modelo de geração de respostas .
Exemplo de comando e resultado parcial
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{"query": { "text": "Compare bigquery with spanner database?"}, "answerGenerationSpec": {
"modelSpec": {
"modelVersion": "preview",
}
} }'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "Cloud Spanner is a fully managed relational database optimized for transactional workloads. BigQuery is a serverless, highly scalable, and cost-effective multi-cloud data warehouse designed for business agility. BigQuery is optimized for ad-hoc analysis and reporting. Both Spanner and BigQuery are built on Google's distributed storage system, Colossus, and their internal cluster management system, Borg. They are also built on Jupiter, Google's in-house custom network hardware and software.\n\nBigQuery can query data stored in Spanner in real time without moving or copying the data. This is possible with BigQuery's query federation support. To run a federated query, you need to configure an external data source in BigQuery that points to the intended Spanner instance. You can then write queries that can be used to populate a BigQuery table on demand or scheduled to run as needed. You can also join the query with another BigQuery result set dynamically.\n\nYou can also use Dataflow to copy data from Spanner to BigQuery. Dataflow is a service that can be used to ingest Spanner data into BigQuery. This is useful for more complex transformations or external dependencies. For example, an online gaming company might use Spanner to store game data and BigQuery to perform analytics on player behavior. They can replicate data from Spanner into BigQuery and perform analytics against local data, or they can use federated queries to retrieve data from Spanner on-demand.\n",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "Compare bigquery with spanner database?"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/ecc0e7547253f4ca3ff3328ce89995af",
"uri": "https://cloud.google.com/blog/topics/developers-practitioners/how-spanner-and-bigquery-work-together-handle-transactional-and-analytical-workloads",
"title": "How Spanner and BigQuery work together to handle transactional and analytical workloads | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "Using Cloud \u003cb\u003eSpanner\u003c/b\u003e and \u003cb\u003eBigQuery\u003c/b\u003e also allows customers to build their \u003cb\u003edata\u003c/b\u003e clouds using Google Cloud, a unified, open approach to \u003cb\u003edata\u003c/b\u003e-driven transformation ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/d7e238f73608a860e00b752ef80e2941",
"uri": "https://cloud.google.com/blog/products/databases/cloud-spanner-gets-stronger-with-bigquery-federated-queries",
"title": "Cloud Spanner gets stronger with BigQuery-federated queries | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "As enterprises compete for market share, their need for real-time insights has given rise to increased demand for transactional \u003cb\u003edatabases\u003c/b\u003e to support \u003cb\u003edata\u003c/b\u003e ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/e10a5a3c267dc61579e7c00fefe656eb",
"uri": "https://cloud.google.com/blog/topics/developers-practitioners/replicating-cloud-spanner-bigquery-scale",
"title": "Replicating from Cloud Spanner to BigQuery at scale | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "... \u003cb\u003eSpanner data\u003c/b\u003e into \u003cb\u003eBigQuery\u003c/b\u003e for analytics. In this post, you will learn how to efficiently use this feature to replicate large tables with high throughput ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/648c220055c1d2ac369165007d9f6650",
"uri": "https://cloud.google.com/blog/products/databases/choosing-cloud-spanner-for-game-development",
"title": "Choosing Cloud Spanner for game development | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "To get started with \u003cb\u003eSpanner\u003c/b\u003e, create a \u003cb\u003edatabase\u003c/b\u003e, or try it out with a \u003cb\u003eSpanner\u003c/b\u003e Qwiklab. ... AlloyDB \u003cb\u003evs\u003c/b\u003e. ... SQL for SQL Server to \u003cb\u003eBigQuery\u003c/b\u003e. By Alexander ...",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
]
},
"answerQueryToken": "NMwKDAivmvy2BhCxnsqdARIkNjZkOTQ0NWEtMDAwMC0yMTBkLTllNmItZjQwMzA0NWRiZDMw"
}
Neste exemplo, é usada a versão de pré-lançamento do modelo em vez do modelo padrão.
Especificar um preâmbulo personalizado
O comando a seguir mostra como definir um preâmbulo para a resposta gerada. Um
preâmbulo contém instruções de linguagem natural para personalizar a resposta. É possível solicitar personalizações, como duração, nível de detalhes, estilo de saída (por exemplo, "simples"), idioma de saída, foco da resposta e formato (por exemplo, tabelas, marcadores e XML). Por exemplo, um preâmbulo pode ser "Explique como você
é uma criança de dez anos de idade."
O preâmbulo pode ter um efeito significativo na qualidade do
responder. Para obter informações sobre o que escrever em preâmbulos e exemplos de boas
preâmbulos, consulte Sobre preâmbulos personalizados .
REST
Para gerar uma resposta usando um modelo diferente do padrão, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"answerGenerationSpec": {
"promptSpec": {
"preamble": "PREAMBLE ",
}
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa.
PREAMBLE
: uma instrução em linguagem natural para
personalizar a resposta. Por exemplo, tente show the answer format in
an ordered list
ou give a very detailed answer
.
Exemplo de comando e resultado
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{
"query": { "text": "what is bigquery?"},
"answerGenerationSpec": {
"promptSpec": {
"preamble": "Explain like you are a ten years old
kid ",
}
}
}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "BigQuery is like a super-powered storage space for your data, but it's in the cloud, not on your computer. It's like a giant warehouse for all your information, but you don't have to build or manage it yourself. You can use BigQuery to find patterns and insights in your data, like figuring out what people like to buy or how many people visited your website. It's like having a super-smart assistant that can help you understand your data better. BigQuery is really good at working with lots of data, even billions of pieces of information. \n",
"steps ": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "What is BigQuery?"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/2d032dc582689e8c0ecea7fc7bfa3189",
"uri": "https://cloud.google.com/bigquery",
"title": "BigQuery enterprise data warehouse | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eBigQuery\u003c/b\u003e is a fully managed, AI-ready data analytics platform that helps you maximize value from your data and is designed to be multi-engine, multi-format, ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/4474f4a5a18ecd611dedfe323dfe55d9",
"uri": "https://cloud.google.com/bigquery/docs/introduction",
"title": "BigQuery overview | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eBigQuery\u003c/b\u003e is a fully managed, AI-ready data platform that helps you manage and analyze your data with built-in features like machine learning, search, ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/c840fdef90d86328f13bbedbdbf0ac10",
"uri": "https://cloud.google.com/bigquery/docs/query-overview",
"title": "Overview of BigQuery analytics | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eBigQuery\u003c/b\u003e lets you save queries and share queries with others. When you save a query, it can be private (visible only to you), shared at the project level ( ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/5cbfab8ce1d5f6ffe45fef22900c9a00",
"uri": "https://cloud.google.com/curated-resources/bigquery",
"title": "Guides BigQuery | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eBigQuery\u003c/b\u003e is Google Cloud's fully managed and serverless enterprise data warehouse solution, designed to help you make informed decisions quickly, so you can ...",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
]
},
"answerQueryToken": "NMwKDAi8hN-2BhC0jMCPARIkNjZkN2I4MzItMDAwMC0yMTliLTkxN2EtMDg5ZTA4MjA0YjFj"
}
Neste exemplo, o preâmbulo solicita uma resposta mais simples que o padrão
podem oferecer.
Incluir citações
O comando a seguir mostra como solicitar citações a serem incluídas no
responder.
REST
Para gerar uma resposta usando um modelo diferente do padrão, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"answerGenerationSpec": {
"includeCitations": INCLUDE_CITATIONS
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa.
INCLUDE_CITATIONS
: especifica se os metadados de citação serão incluídos na resposta. O valor padrão é false
.
Exemplo de comando e resultado parcial
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{"query": { "text": "What is SQL"}, "answerGenerationSpec": {
"includeCitations": true
}
}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "SQL stands for Structured Query Language and is a programming language used to manage, query, and retrieve data in a relational database. It is the standard language used by relational database management systems (RDBMS) such as PostgreSQL, SQL Server, MySQL, and Oracle Database. SQL statements are written in a statement format for queries and other database operations, allowing users to manipulate data in relational database tables. SQL is used to create and update the structure of tables, read and write data, manage user permissions, and perform administrative tasks. While originally created for relational databases, SQL is now a foundation for many technology capabilities, making SQL knowledge essential for many technology roles. \n",
"citations": [
{
"endIndex": "137",
"sources": [
{
"referenceId": "0"
},
{
"referenceId": "1"
}
]
},
{
"startIndex": "138",
"endIndex": "437",
"sources": [
{
"referenceId": "3"
}
]
},
{
"startIndex": "438",
"endIndex": "575",
"sources": [
{
"referenceId": "2"
}
]
},
{
"startIndex": "576",
"endIndex": "742",
"sources": [
{
"referenceId": "3"
}
]
}
],
"references": [
{
"chunkInfo": {
"content": "There may be a second table that stores visit information. A relational database uses a unique ID for each row to maintain the linked patient information across the two tables. This way, you can quickly look up the visits of each patient. Sign up for a free trial for any of Google Cloud's SQL databases, which include AlloyDB, Cloud SQL, and Spanner. Get started for free What is SQL? SQL (Structured Query Language) is a programming language used to store, retrieve, and manage data in a relational database. SQL statements are English-like, making the language accessible to software developers, data analysts, and other practitioners. Benefits of SQL databases Enterprises choose SQL databases for being: Efficient. Relational databases are incredibly efficient in managing complex queries. Fast. SQL databases can retrieve large amounts of data, quickly. This makes them highly desirable for real-time transactional data. Reliable. SQL databases provide a high degree of data integrity and are ACID-compliant. SQL database engines There are numerous SQL database engines (products) used to build software applications. Some of the most popular include PostgreSQL, MySQL, SQL Server, and Oracle. Some database engines are open source while others are commercial offerings. ",
"relevanceScore": 0.9,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/7218ff4f57328d86059246d4af3a9953",
"uri": "https://cloud.google.com/discover/what-are-sql-databases",
"title": "SQL Databases | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "PostgreSQL vs. SQL Server: What's the difference? | Google Cloud Page Contents Topics PostgreSQL vs. SQL PostgreSQL vs SQL Server: What are the key differences? Trying to find the right database for your applications? When it comes to choosing a database technology, the most common SQL options to consider are PostgreSQL vs. SQL Server. While both systems share many core features, there are some key differences—the major one being that PostgreSQL is open source and SQL Server is owned by Microsoft. Today, it is more vital than ever for companies to be able to manage, store, and activate data for modern business operations. With the growing assortment of databases available to choose from, it can be overwhelming to pick the right one for your applications. The most important thing to remember is that no single database will be a good match for every project requirement, so it's critical to understand the option that will work best for your specific use case. So, what is PostgreSQL vs. SQL Server? In this short guide, we'll discuss the basic differences between PostgreSQL and SQL Server. Get started for freeStay informed What is SQL? Structured Query Language or SQL, as it's more commonly known, is a programming language used to manage, query, and retrieve data in a relational database. ",
"relevanceScore": 0.8,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/f7cd9afab1282a9f57cdcee1885bb4c6",
"uri": "https://cloud.google.com/learn/postgresql-vs-sql",
"title": "PostgreSQL vs. SQL Server: What's the difference? | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "SQL Databases | Google Cloud Page Contents Topics What are SQL databases? What are SQL databases? A SQL database, also known as a relational database, is a system that stores and organizes data into highly structured tables of rows and columns. These databases offer Structured Query Language (SQL) to read and write the data, and are categorized as relational database management systems (RDBMS). SQL statements are used to create and update the structure of tables, read and write data, manage user permissions, and perform administrative tasks. For example, a CREATE statement is used to create a table, an INSERT statement adds a new row to a table, and a SELECT statement performs a database query. Statements that make structural or administrative changes are usually reserved for software developers and administrators, while read and write operations are performed by end-user applications. A relational database maintains the ability to link information across multiple tables. This format makes it easy to quickly gain insights about the relationships between various columns or data points in these tables. A relational database can create indexes for particular columns for faster lookups. For example, a healthcare facility might maintain a table containing rows of patient information, where each row is one patient and the columns contain data points, such as the patient's name, insurance information, and contact details. ",
"relevanceScore": 0.8,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/7218ff4f57328d86059246d4af3a9953",
"uri": "https://cloud.google.com/discover/what-are-sql-databases",
"title": "SQL Databases | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "It is the standard language used by relational database management systems (RDBMS), including PostgreSQL, SQL Server, MySQL, and Oracle Database. SQL typically uses commands written in statement format for queries and other database operations, which allow users to manipulate data in relational database tables. While originally created for relational databases, SQL acts as a foundation for many of today's technology capabilities, making SQL knowledge an essential skill for many technology roles today, including data analysts, database engineers, and even backend programming. However, you will find that there are different variants of SQL depending on the database or database management system that you choose. What is Microsoft SQL Server? SQL Server is a leading RDBMS that is built on top of SQL and developed by Microsoft. It is used to manage and store data to support numerous enterprise use cases for business intelligence, transaction processing, data analytics, and machine learning services. SQL Server has a row-based table structure that allows you to connect related data elements from different tables without having to store data multiple times in a database. In general, Microsoft SQL Server is known for its high availability, fast performance when handling large workloads, and easy integration with other applications to gain business intelligence across your entire data estate. For more information, we recommend reviewing the official SQL Server documentation. ",
"relevanceScore": 0.8,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/f7cd9afab1282a9f57cdcee1885bb4c6",
"uri": "https://cloud.google.com/learn/postgresql-vs-sql",
"title": "PostgreSQL vs. SQL Server: What's the difference? | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "Send feedback The GoogleSQL language in Spanner bookmark_borderbookmark Stay organized with collections Save and categorize content based on your preferences. Dismiss Got it GoogleSQL is the new name for Google Standard SQL! New name, same great SQL dialect. This page provides an overview of supported statements in GoogleSQL. GoogleSQL is an ANSI compliant Structured Query Language (SQL) which includes the following types of supported statements: Query statements, also known as Data Query Language (DQL) statements, are the primary method to analyze data in Spanner. They scan one or more tables or expressions and return the computed result rows. Data Definition Language (DDL) statements let you create and modify database objects such as tables, views, and database roles. Data Manipulation Language (DML) statements enable you to update, insert, and delete data from your Spanner tables. Data Access Control statements let you grant and revoke access privileges at the table and column level. Transaction Control statements allow you to manage transactions for data modifications. Was this helpful? Send feedback Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. ",
"relevanceScore": 0.7,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/0c5c094170756eeb6bdfec6eb5c7d081",
"uri": "https://cloud.google.com/spanner/docs/reference/standard-sql/overview",
"title": "The GoogleSQL language in Spanner | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "FAQ Expand all What is Cloud SQL? Cloud SQL is a service that delivers fully managed relational databases in the cloud. It offers MySQL, PostgreSQL, and SQL Server database engines. How is Cloud SQL different from other cloud databases? Cloud SQL is valued for its openness, ease of use, security, cost-efficiency, and Google Cloud integration—in fact, more than 95% of Google Cloud's top 100 customers use it. If you're comparing PostgreSQL options on Google Cloud, view our comparison chart. What's the difference between the Enterprise and Enterprise Plus editions? For PostgreSQL, the Enterprise Plus edition brings enhanced availability, performance, and data protection capabilities. Specifically, it provides a 99.99% availability SLA with near-zero downtime maintenance, optimized hardware and software configurations, intelligent data caching for read-intensive transactional workloads, a configurable data cache option and 35 days of log retention. For MySQL, the Enterprise Plus edition brings enhanced availability, performance, and data protection capabilities. Specifically, it provides a 99.99% availability SLA with near-zero downtime maintenance, optimized hardware and software configurations, intelligent data caching for read-intensive transactional workloads, a configurable data cache option, 35 days of log retention and advanced disaster recovery capabilities like orchestrated failover and switchback. ",
"relevanceScore": 0.7,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/931f2c8e19ed54a407857f1cad3b5aaa",
"uri": "https://cloud.google.com/sql",
"title": "Cloud SQL for MySQL, PostgreSQL, and SQL Server | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "PostgreSQL versus SQL PostgreSQL is an open-source, object-relational database (ORDBMS) designed for enterprise-level performance and is valued for its reliability and robust features. Its long history of development and its use of SQL makes it one of the most popular open source databases worldwide. Its default procedural language is an extension of pgSQL (PL/pgSQL), with procedural language extensions of Tcl, Perl, and Python included in the standard distribution (written as PL/Tcl, PL/Perl, and PL/Python). Many more languages are supported through extensions, including Java, Ruby, C, C++, Delphi, and JavaScript. For a more in-depth comparison, visit our PostgreSQL versus SQL guide. MySQL versus SQL MySQL is a popular open source relational database created in 1995 and currently sponsored by Oracle. It supports SQL queries and can be administered either through a graphical user interface (GUI) or a command line. MySQL can be deployed manually on a physical machine or through a cloud service provider. Enterprises are increasingly choosing fully managed services to reduce the maintenance burden of their databases. What is SQL Server? SQL Server is a Microsoft-owned database that runs SQL queries. Dive into the differences between PostgreSQL and SQL Server. ",
"relevanceScore": 0.6,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/7218ff4f57328d86059246d4af3a9953",
"uri": "https://cloud.google.com/discover/what-are-sql-databases",
"title": "SQL Databases | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "Send feedback On this page BigQuery SQL dialects Changing from the default dialect What's next Introduction to SQL in BigQuery bookmark_borderbookmark Stay organized with collections Save and categorize content based on your preferences. Dismiss Got it GoogleSQL is the new name for Google Standard SQL! New name, same great SQL dialect. This document provides an overview of supported statements and SQL dialects in BigQuery. GoogleSQL is an ANSI compliant Structured Query Language (SQL) which includes the following types of supported statements: Query statements, also known as Data Query Language (DQL) statements, are the primary method to analyze data in BigQuery. They scan one or more tables or expressions and return the computed result rows. Procedural language statements are procedural extensions to GoogleSQL that allow you to execute multiple SQL statements in one request. Procedural statements can use variables and control-flow statements, and can have side effects. Data Definition Language (DDL) statements let you create and modify database objects such as tables, views, functions, and row-level access policies. Data Manipulation Language (DML) statements enable you to update, insert, and delete data from your BigQuery tables. Data Control Language (DCL) statements let you control BigQuery system resources such as access and capacity. Transaction Control Language (TCL) statements allow you to manage transactions for data modifications. ",
"relevanceScore": 0.6,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/2f6fc3e29873518196cb50195d7ded45",
"uri": "https://cloud.google.com/bigquery/docs/introduction-sql",
"title": "Introduction to SQL in BigQuery | Google Cloud"
}
}
},
{
"chunkInfo": {
"content": "Database administration Cloud SQL pricing Connect to a Cloud SQL managed database Cloud SQL updates Configuration updates System updates What's next Home Cloud SQL Documentation Guides Was this helpful? Send feedback Cloud SQL overview bookmark_borderbookmark Stay organized with collections Save and categorize content based on your preferences. Dismiss Got it On this page Database configurations with Cloud SQL Use cases for Cloud SQL What Cloud SQL provides What is a Cloud SQL instance? Database administration Cloud SQL pricing Connect to a Cloud SQL managed database Cloud SQL updates Configuration updates System updates What's next Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL, and SQL Server. This frees you from database administration tasks so that you have more time to manage your data. This page discusses basic concepts and terminology for Cloud SQL, which provides SQL data storage for Google Cloud. For a more in-depth explanation of key concepts, see the key terms and features pages. For information about how Cloud SQL databases compare with one another, see Cloud SQL feature support by database engine. Database configurations with Cloud SQL The following video shows you the benefits of using Cloud SQL. ",
"relevanceScore": 0.6,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/4098ae11bfa400e8f1b8e9ba59d2b71b",
"uri": "https://cloud.google.com/sql/docs/introduction",
"title": "Cloud SQL overview"
}
}
},
{
"chunkInfo": {
"content": "Cloud SQL documentation View all product documentation Cloud SQL is a fully-managed database service that helps you set up, maintain, manage, and administer your relational databases on Google Cloud Platform. You can use Cloud SQL with MySQL, PostgreSQL, or SQL Server. Not sure what database option is right for you? Learn more about our database services. Learn more about Cloud SQL. Documentation resources Find quickstarts and guides, review key references, and get help with common issues. format_list_numbered Guides Cloud SQL overview Database engine feature support MySQL PostgreSQL SQL Server find_in_page Reference gcloud commands REST API Client libraries info Resources Pricing Release notes Resources Try Cloud SQL for yourself Create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads. Try Cloud SQL free Was this helpful? Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Last updated 2024-08-29 UTC. ",
"relevanceScore": 0.5,
"documentMetadata": {
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/37935181d99a6ad3b4897e673a7a7986",
"uri": "https://cloud.google.com/sql/docs",
"title": "Cloud SQL documentation"
}
}
}
],
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "What is SQL?"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/7218ff4f57328d86059246d4af3a9953",
"uri": "https://cloud.google.com/discover/what-are-sql-databases",
"title": "SQL Databases | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eSQL\u003c/b\u003e (Structured Query Language) is a programming language used to store, retrieve, and manage data in a relational database. \u003cb\u003eSQL\u003c/b\u003e statements are English-like, ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/f7cd9afab1282a9f57cdcee1885bb4c6",
"uri": "https://cloud.google.com/learn/postgresql-vs-sql",
"title": "PostgreSQL vs. SQL Server: What's the difference? | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eSQL\u003c/b\u003e typically uses commands written in statement format for queries and other database operations, which allow users to manipulate data in relational database ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/3afdede140d0906c2146a2f2b3a7821e",
"uri": "https://cloud.google.com/blog/topics/developers-practitioners/what-cloud-sql",
"title": "What is Cloud SQL? | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "It is a fully managed relational database for MySQL, PostgreSQL and \u003cb\u003eSQL\u003c/b\u003e Server. It reduces maintenance cost and automates database provisioning, storage ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/0c5c094170756eeb6bdfec6eb5c7d081",
"uri": "https://cloud.google.com/spanner/docs/reference/standard-sql/overview",
"title": "The GoogleSQL language in Spanner | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eGoogleSQL\u003c/b\u003e is the new name for Google Standard \u003cb\u003eSQL\u003c/b\u003e! New name, same great \u003cb\u003eSQL\u003c/b\u003e dialect. This page provides an overview of supported statements in \u003cb\u003eGoogleSQL\u003c/b\u003e.",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
]
},
"answerQueryToken": "NMwKDAiFm_y2BhC_nfrYAxIkNjZkYjg3NjItMDAwMC0yZTBkLTg0ZDAtMDg5ZTA4MmRjYjg0"
}
Definir o código do idioma da resposta
O comando a seguir mostra como definir o código do idioma para as respostas.
REST
Para gerar uma resposta usando um modelo diferente do padrão, faça o seguinte:
Execute o seguinte comando curl:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"answerGenerationSpec": {
"answerLanguageCode": "ANSWER_LANGUAGE_CODE "
}
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa que você quer consultar.
QUERY
: uma string de texto livre que contém a
pergunta ou consulta de pesquisa.
ANSWER_LANGUAGE_CODE
: um código de idioma para a
responder. Use tags de idioma definidas por BCP47: Tags for
Como identificar idiomas (em inglês).
Exemplo de comando e resultado
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer" \
-d '{"query": { "text": "What is SQL"}, "answerGenerationSpec": {
"answerLanguageCode": "es"
}
}'
{
"answer": {
"state": "SUCCEEDED",
"answerText": "SQL, que significa Structured Query Language, es un lenguaje de programación utilizado para almacenar, recuperar y administrar datos en una base de datos relacional. Las instrucciones de SQL son similares al inglés, lo que hace que el lenguaje sea accesible para desarrolladores de software, analistas de datos y otros profesionales. Las bases de datos SQL se utilizan para administrar y almacenar datos para apoyar numerosos casos de uso empresariales, como la inteligencia empresarial, el procesamiento de transacciones, el análisis de datos y los servicios de aprendizaje automático. SQL es el lenguaje estándar utilizado por los sistemas de gestión de bases de datos relacionales (RDBMS), incluidos PostgreSQL, SQL Server, MySQL y Oracle Database. SQL se utiliza para crear y actualizar la estructura de las tablas, leer y escribir datos, administrar los permisos de los usuarios y realizar tareas administrativas. \n",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "What is SQL?"
},
"observation": {
"searchResults": [
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/7218ff4f57328d86059246d4af3a9953",
"uri": "https://cloud.google.com/discover/what-are-sql-databases",
"title": "SQL Databases | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eSQL\u003c/b\u003e (Structured Query Language) is a programming language used to store, retrieve, and manage data in a relational database. \u003cb\u003eSQL\u003c/b\u003e statements are English-like, ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/f7cd9afab1282a9f57cdcee1885bb4c6",
"uri": "https://cloud.google.com/learn/postgresql-vs-sql",
"title": "PostgreSQL vs. SQL Server: What's the difference? | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eSQL\u003c/b\u003e typically uses commands written in statement format for queries and other database operations, which allow users to manipulate data in relational database ...",
"snippetStatus": "SUCCESS"
}
]
},
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/3afdede140d0906c2146a2f2b3a7821e",
"uri": "https://cloud.google.com/blog/topics/developers-practitioners/what-cloud-sql",
"title": "What is Cloud SQL? | Google Cloud Blog",
"snippetInfo": [
{
"snippet": "It is a fully managed relational database for MySQL, PostgreSQL and \u003cb\u003eSQL\u003c/b\u003e Server. It reduces maintenance cost and automates database provisioning, storage ...",
"snippetStatus": "SUCCESS"
}
]
},
...
{
"document": "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/0c5c094170756eeb6bdfec6eb5c7d081",
"uri": "https://cloud.google.com/spanner/docs/reference/standard-sql/overview",
"title": "The GoogleSQL language in Spanner | Google Cloud",
"snippetInfo": [
{
"snippet": "\u003cb\u003eGoogleSQL\u003c/b\u003e is the new name for Google Standard \u003cb\u003eSQL\u003c/b\u003e! New name, same great \u003cb\u003eSQL\u003c/b\u003e dialect. This page provides an overview of supported statements in \u003cb\u003eGoogleSQL\u003c/b\u003e.",
"snippetStatus": "SUCCESS"
}
]
}
]
}
}
]
}
]
},
"answerQueryToken": "NMwKDAjim_y2BhDftIjEAhIkNjZkOTQ0NWQtMDAwMC0yMTBkLTllNmItZjQwMzA0NWRiZDMw"
}
Neste exemplo, embora os documentos de origem estejam em inglês, a resposta é
disponíveis em espanhol.
Comandos para perguntas de acompanhamento
Acompanhamentos são consultas de várias interações. Após a primeira consulta em uma sessão de acompanhamento,
"se vira" levar em consideração as interações anteriores. Com as perguntas de acompanhamento, o método de resposta
também pode sugerir perguntas relacionadas, que os usuários podem escolher em vez de
inserir as próprias perguntas de acompanhamento.
Todos os recursos de respostas e acompanhamentos descritos nas seções anteriores, como
citações, filtros, SafeSearch, ignorar determinados tipos de consultas e usar um
preâmbulo para personalizar respostas, podem ser aplicados junto com os acompanhamentos.
Exemplo de uma sessão de acompanhamento
Confira a seguir um exemplo de uma sessão com acompanhamentos. Suponha que você queira
saber sobre férias no México:
Turno 1 :
Você : Qual é a melhor época do ano para passar as férias no México?
Resposta com acompanhamento : o melhor período para tirar férias no México é durante a estação seca, que vai de novembro a abril.
Turno 2:
Você: Qual é a taxa de câmbio?
Resposta com acompanhamento :1 USD é igual a aproximadamente 17,65 pesos mexicanos.
Turno 3 :
Sem acompanhamento, sua pergunta: "Qual é a taxa de câmbio?" não seria
porque a pesquisa normal não saberia que você queria a comida mexicana
taxa de câmbio. Da mesma forma, sem acompanhamentos, não haveria o contexto
necessário para fornecer as temperaturas especificamente para o México.
Quando você pergunta: "Qual é a melhor época do ano para passar as férias em
México?", além de responder às suas perguntas, as respostas e os acompanhamentos podem sugerir outras
perguntas que podem ser feitas, como "Qual é o mês mais barato
de férias no México?" e "Quais são os meses de turismo no México?".
Depois que o recurso de perguntas relacionadas é ativado, as perguntas são retornadas como
strings no ConverseConversationResponse .
Sobre sessões
Para entender como os acompanhamentos funcionam na Vertex AI para Pesquisa, você precisa
entender melhor as sessões.
Uma sessão é composta por consultas de texto fornecidas por um usuário e respostas fornecidas pela Vertex AI para Pesquisa.
Esses pares de consulta e resposta às vezes são chamados de turnos . Na
exemplo anterior, a segunda rodada é composta por "Qual é a taxa de câmbio?"
e "1 USD é igual a aproximadamente 17,65 pesos mexicanos".
As sessões são armazenadas com o app.
No app, uma sessão é representada pelo recurso
de sessão .
Além de conter as mensagens de consulta e resposta, o recurso de sessão
tem:
Um nome exclusivo (o ID da sessão).
Um estado (em andamento ou concluído).
Um pseudoID do usuário, que é um ID de visitante que rastreia o usuário. Ele pode ser
atribuído de forma programática.
Um horário de início e um de término.
Uma vez, que é um par de consulta e resposta.
Armazenar informações da sessão e receber respostas
Você pode usar a linha de comando para gerar respostas de pesquisa e respostas
e armazená-los com cada consulta em uma sessão.
REST
Para usar a linha de comando para criar uma sessão e gerar respostas a partir do
a entrada do usuário, siga estas etapas:
Especifique o app em que você quer armazenar a sessão:
curl -X POST \
-H "Authorization: Bearer $( gcloud auth print-access-token) " \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions" \
-d '{
"userPseudoId": "USER_PSEUDO_ID "
}'
Substitua:
PROJECT_ID : o ID do seu projeto do Google Cloud.
APP_ID : o ID do app da Vertex AI para Pesquisa.
USER_PSEUDO_ID : é um identificador exclusivo para rastrear um
visitante da pesquisa. Por exemplo, é possível implementar isso com um cookie HTTP,
que identifica exclusivamente um visitante em um único dispositivo.
Exemplo de comando e resultado
curl -X POST -H "Authorization: Bearer $( gcloud auth print-access-token) "
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/sessions"
-d '{
"userPseudoId": "test_user"
}'
{
"name" : "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943" ,
"state" : "IN_PROGRESS" ,
"userPseudoId" : "test_user" ,
"startTime" : "2024-09-13T18:47:10.465311Z" ,
"endTime" : "2024-09-13T18:47:10.465311Z"
}
Anote o ID da sessão, os números no final do campo name:
na
Resposta de JSON. No exemplo de resultado, o ID é 5386462384953257772
.
Você vai precisar desse ID na próxima etapa.
Gere uma resposta e adicione a uma sessão no seu app:
curl -X POST \
-H "Authorization: Bearer $( gcloud auth print-access-token) " \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /servingConfigs/default_search:answer" \
-d '{
"query": { "text": "QUERY "},
"session": "projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions/SESSION_ID ",
"searchSpec":{ "searchParams": {"filter": "FILTER "} }
}'
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa.
QUERY
: uma string de texto livre que contém o
pergunta ou consulta de pesquisa.
SESSION_ID
: o ID da sessão que você
criado na etapa 1. Esses são os dígitos no final do campo name:
, conforme indicado na etapa 2. Para uma sessão, use a mesma
ID de sessão em todos os turnos.
FILTER
: um campo de texto para filtrar a pesquisa
usando uma expressão de filtro. O valor padrão é uma string vazia. A maneira como você constrói o filtro varia de acordo com se você tem dados não estruturados com metadados, dados estruturados ou dados do site. Para mais informações,
consulte Filtrar
pesquisa genérica para dados estruturados ou não estruturados e Filtrar
Pesquisa no site .
Exemplo de comando e resultado
curl -X POST -H "Authorization: Bearer $( gcloud auth print-access-token) "
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/my-project-123/locations/global/collections/default_collection/engines/my-app/servingConfigs/default_search:answer"
-d '{
"query": { "text": "Compare bigquery with spanner database?"},
"session": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943",
}'
{
"answer" : {
"name" : "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943/answers/4861507376861383072" ,
"state" : "SUCCEEDED" ,
"answerText" : "BigQuery and Spanner are both powerful tools that can be used together to handle transactional and analytical workloads. Spanner is a fully managed relational database optimized for transactional workloads, while BigQuery is a serverless data warehouse designed for business agility. Spanner provides seamless replication across regions in Google Cloud and processes over 1 billion requests per second at peak. BigQuery analyzes over 110 terabytes of data per second. Users can leverage federated queries to read data from Spanner and write to a native BigQuery table. \n" ,
"steps" : [
{
"state" : "SUCCEEDED" ,
"description" : "Rephrase the query and search." ,
"actions" : [
{
"searchAction" : {
"query" : "Compare bigquery with spanner database?"
} ,
"observation" : {
"searchResults" : [
{
"document" : "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/ecc0e7547253f4ca3ff3328ce89995af" ,
"uri" : "https://cloud.google.com/blog/topics/developers-practitioners/how-spanner-and-bigquery-work-together-handle-transactional-and-analytical-workloads" ,
"title" : "How Spanner and BigQuery work together to handle transactional and analytical workloads | Google Cloud Blog" ,
"snippetInfo" : [
{
"snippet" : "Using Cloud \u003cb\u003eSpanner\u003c/b\u003e and \u003cb\u003eBigQuery\u003c/b\u003e also allows customers to build their \u003cb\u003edata\u003c/b\u003e clouds using Google Cloud, a unified, open approach to \u003cb\u003edata\u003c/b\u003e-driven transformation ..." ,
"snippetStatus" : "SUCCESS"
}
]
} ,
{
"document" : "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/d7e238f73608a860e00b752ef80e2941" ,
"uri" : "https://cloud.google.com/blog/products/databases/cloud-spanner-gets-stronger-with-bigquery-federated-queries" ,
"title" : "Cloud Spanner gets stronger with BigQuery-federated queries | Google Cloud Blog" ,
"snippetInfo" : [
{
"snippet" : "As enterprises compete for market share, their need for real-time insights has given rise to increased demand for transactional \u003cb\u003edatabases\u003c/b\u003e to support \u003cb\u003edata\u003c/b\u003e ..." ,
"snippetStatus" : "SUCCESS"
}
]
} ,
{
"document" : "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/e10a5a3c267dc61579e7c00fefe656eb" ,
"uri" : "https://cloud.google.com/blog/topics/developers-practitioners/replicating-cloud-spanner-bigquery-scale" ,
"title" : "Replicating from Cloud Spanner to BigQuery at scale | Google Cloud Blog" ,
"snippetInfo" : [
{
"snippet" : "... \u003cb\u003eSpanner data\u003c/b\u003e into \u003cb\u003eBigQuery\u003c/b\u003e for analytics. In this post, you will learn how to efficiently use this feature to replicate large tables with high throughput ..." ,
"snippetStatus" : "SUCCESS"
}
]
} ,
...
{
"document" : "projects/123456/locations/global/collections/default_collection/dataStores/my-data-store/branches/0/documents/8100ad36e1cac149eb9fc180a41d8f25" ,
"uri" : "https://cloud.google.com/blog/products/gcp/from-nosql-to-new-sql-how-spanner-became-a-global-mission-critical-database" ,
"title" : "How Spanner became a global, mission-critical database | Google Cloud Blog" ,
"snippetInfo" : [
{
"snippet" : "... SQL \u003cb\u003evs\u003c/b\u003e. NoSQL dichotomy may no longer be relevant." The \u 003cb\u 003eSpanner\u 003c/b\u 003e SQL query processor, while recognizable as a standard implementation, has unique ...",
" snippetStatus": " SUCCESS"
}
]
}
]
}
}
]
}
]
},
" session": {
" name": " projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943",
" state": " IN_PROGRESS",
" userPseudoId": " test_user",
" turns": [
{
" query": {
" queryId": " projects/123456/locations/global/questions/741830",
" text": " Compare bigquery with spanner database?"
},
" answer": " projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943/answers/4861507376861383072"
}
],
" startTime": " 2024 -09-13T18:47:10.465311Z",
" endTime": " 2024 -09-13T18:47:10.465311Z"
},
" answerQueryToken": " NMwKDAjFkpK3BhDU24uZAhIkNjZlNDIyZWYtMDAwMC0yMjVmLWIxMmQtZjQwMzA0M2FkYmNj"
}
Repita a etapa 3 para cada nova consulta na sessão.
Acessar uma sessão do repositório de dados
O comando a seguir mostra como chamar o método get
e
para receber uma sessão do repositório de dados.
REST
Para receber uma sessão de um repositório de dados, faça o seguinte:
Execute o seguinte comando curl:
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions/SESSION_ID "
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app Vertex AI para Pesquisa.
SESSION_ID
: o ID da sessão que você
quer receber.
Excluir uma sessão do app
O comando a seguir mostra como chamar o método delete
e
excluir uma sessão do armazenamento de dados.
Por padrão, as sessões com mais de 60 dias são excluídas automaticamente.
No entanto, se você quiser excluir uma sessão específica, por exemplo, se ela
contiver conteúdo sensível, use essa chamada de API para excluí-la.
REST
Para excluir uma sessão de um app, faça o seguinte:
Execute o seguinte comando curl:
curl -X DELETE -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions/SESSION_ID "
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa.
SESSION_ID
: o ID da sessão que você
quer excluir.
Exemplo de comando e resultado
curl -X DELETE -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943"
{}
Atualizar uma sessão
Há vários motivos para atualizar uma sessão. Por exemplo,
para fazer uma das seguintes ações:
Marcar uma sessão como concluída
Mesclar as mensagens de uma sessão em outra
Mudar o pseudoID de um usuário
O comando a seguir mostra como chamar o método patch
e
para atualizar uma sessão no repositório de dados.
REST
Para atualizar uma sessão usando um app, faça o seguinte:
Execute o seguinte comando curl:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions/SESSION_ID ?updateMask=state" \
-d '{
"state": "NEW_STATE "
}'
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app Vertex AI para Pesquisa.
SESSION_ID
: o ID da sessão que você
quer atualizar.
NEW_STATE
: o novo valor do estado, por
exemplo, IN_PROGRESS
.
Exemplo de comando e resultado
curl -X PATCH -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943?updateMask=state"
-d '{
"state": "IN_PROGRESS"
}'
{
"name": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943",
"state": "IN_PROGRESS",
"userPseudoId": "test_user",
"turns": [
{
"query": {
"queryId": "projects/123456/locations/global/questions/741830",
"text": "Compare bigquery with spanner database?"
},
"answer": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943/answers/4861507376861383072"
}
],
"startTime": "2024-09-13T18:47:10.465311Z",
"endTime": "2024-09-13T18:49:41.579151Z"
}
Este exemplo muda o estado da sessão para aberto (em andamento). Siga um padrão semelhante para atualizar o userPseudoId
.
Listar todas as sessões
O comando a seguir mostra como chamar o método list
e
listar as sessões no repositório de dados.
REST
Para listar as sessões de um app, faça o seguinte:
Execute o seguinte comando curl:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions"
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa.
Exemplo de comando e resultado
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/123456/locations/global/collections/default_collection/engines/my-app/sessions"
{
"sessions": [
{
"name": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/10000135306311111817",
"state": "IN_PROGRESS",
"turns": [
{
"query": {
"queryId": "projects/123456/locations/global/questions/10000135306311114276",
"text": "bugs reported by tiktok on grounding"
}
}
],
"startTime": "2024-09-03T00:38:40.338623Z",
"endTime": "2024-09-03T00:38:40.338623Z"
},
{
"name": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/10000827040519035859",
"state": "IN_PROGRESS",
"turns": [
{
"query": {
"queryId": "projects/123456/locations/global/questions/10000827040519033518",
"text": "GDM models"
}
}
],
"startTime": "2024-07-19T15:53:06.521775Z"
},
{
"name": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/10003910515245149877",
"state": "IN_PROGRESS",
"turns": [
{
"query": {
"queryId": "projects/123456/locations/global/questions/10003910515245148378",
"text": "gyorgyattila"
},
"answer": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/10003910515245149877/answers/17036357111873257990"
}
],
"startTime": "2024-08-08T11:40:04.632463Z",
"endTime": "2024-08-08T11:40:04.632463Z"
},
...
{
"name": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/10198752942940073431",
"state": "IN_PROGRESS",
"turns": [
{
"query": {
"queryId": "projects/123456/locations/global/questions/10198752942940071818",
"text": "hello"
},
"answer": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/10198752942940073431/answers/13411441797796265380"
}
],
"startTime": "2024-08-14T17:30:21.203439Z",
"endTime": "2024-08-14T17:30:21.203439Z"
}
],
"nextPageToken": "IDEDgIwL_vuieLC"
}
A resposta contém uma lista de sessões e o nextPageToken. Se nenhum
nextPageToken for retornado, não haverá mais sessões para listar. Página padrão
é 50.
Listar sessões de um usuário
O comando a seguir mostra como chamar o método list
para
Lista as sessões associadas a um usuário ou visitante.
REST
Para listar sessões associadas a um usuário ou visitante, faça o seguinte:
Execute o seguinte comando curl:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions?filter=userPseudoId=USER_PSEUDO_ID "
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa.
USER_PSEUDO_ID
: o pseudoID do usuário.
quais sessões você quer listar.
Exemplo de comando e resultado
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/123456/locations/global/collections/default_collection/engines/my-app/sessions?filter=userPseudoId=test_user"
{
"sessions": [
{
"name": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943",
"state": "IN_PROGRESS",
"userPseudoId": "test_user",
"turns": [
{
"query": {
"queryId": "projects/123456/locations/global/questions/741830",
"text": "Compare bigquery with spanner database?"
},
"answer": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943/answers/4861507376861383072"
}
],
"startTime": "2024-09-13T18:47:10.465311Z",
"endTime": "2024-09-13T18:49:41.579151Z"
}
]
}
Neste exemplo, há uma sessão associada ao test_user. O
as consultas e respostas da sessão são listadas.
Listar sessões para um usuário e estado
O comando a seguir mostra como chamar o método list
para
listar sessões em um determinado estado para um usuário específico.
REST
Para listar as sessões de um usuário que estão abertas ou fechadas e que estão associadas a um determinado
usuário ou visitante, faça o seguinte:
Execute o seguinte comando curl:
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID /locations/global/collections/default_collection/engines/APP_ID /sessions?filter=userPseudoId=USER_PSEUDO_ID %20AND%20state=STATE "
Substitua:
PROJECT_ID
: o ID do seu projeto do Google Cloud.
APP_ID
: o ID do app da Vertex AI para Pesquisa.
USER_PSEUDO_ID
: o pseudo-ID do usuário
cujas sessões você quer listar.
STATE
: o estado da sessão:
STATE_UNSPECIFIED
(fechada ou desconhecida) ou
IN_PROGRESS
(aberto).
Exemplo de comando e resultado
curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
"https://discoveryengine.googleapis.com/v1/projects/123456/locations/global/collections/default_collection/engines/my-app/sessions?filter=userPseudoId=test_user%20AND%20state=IN_PROGRESS"
{
"sessions": [
{
"name": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943",
"state": "IN_PROGRESS",
"userPseudoId": "test_user",
"turns": [
{
"query": {
"queryId": "projects/123456/locations/global/questions/741830",
"text": "Compare bigquery with spanner database?"
},
"answer": "projects/123456/locations/global/collections/default_collection/engines/my-app/sessions/16002628354770206943/answers/4861507376861383072"
}
],
"startTime": "2024-09-13T18:47:10.465311Z",
"endTime": "2024-09-13T18:49:41.579151Z"
}
]
}
O resultado esperado é uma resposta vazia.