How to use Google's Gen AI Multi-turn search API in python

480 Views Asked by At

Currently I am using Google Discovery engine regular search but I want to use this multi-turn search which saves the context of my previous queries but I am unable to find any documentation regarding how to implement it in python, link: https://cloud.google.com/generative-ai-app-builder/docs/multi-turn-search

My current Implementation:

def genappbuilder_search(
        search_query: str = "",
        project_id: str = project_id,
        location: str = location,
        search_engine_id: str = search_engine_id,
        serving_config_id: str = serving_config_id,
) -> List[discoveryengine.SearchResponse.SearchResult]:

    client = discoveryengine.SearchServiceClient()

    serving_config = client.serving_config_path(
        project=project_id,
        location=location,
        data_store=search_engine_id,
        serving_config=serving_config_id,
    )

    request = discoveryengine.SearchRequest(
        serving_config=serving_config, query=search_query, page_size=5
    )

    response = client.search(request)
    return response.results
1

There are 1 best solutions below

2
On

You can use the conversation notebook in this repository to use Multi-Turn (Conversational) Search in Python.

https://github.com/rasalt/snippets_es/

Official code samples should be added to the documentation soon.