Hi!
We are trying to use Vertex AI for our internal system and build a search app with DiscoveryEngine_v1 (0.13.11) using the Python SDK.
While reviewing the Python SDK reference, we noticed that sending a search request to the SearchService.Search method with an unset order_by field in the SearchRequest object will return a SearchResponse object ordered by relevance.
However, the current script doesn’t work as the reference describes.
client_options = (
ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
if location != "global"
else None
)
client = SearchServiceClient(client_options=client_options)
snippet_spec = SearchRequest.ContentSearchSpec.SnippetSpec(
return_snippet=True
)
preamble_text = (
"PREAMBLE_TEXT"
)
model_prompt_spec = (
SearchRequest.ContentSearchSpec.SummarySpec.ModelPromptSpec(
preamble=preamble_text
)
)
summary_spec = SearchRequest.ContentSearchSpec.SummarySpec(
summary_result_count=10,
include_citations=False,
ignore_adversarial_query=False,
ignore_non_summary_seeking_query=False,
ignore_low_relevant_content=False,
ignore_jail_breaking_query=False,
model_prompt_spec=model_prompt_spec,
model_spec=SearchRequest.ContentSearchSpec.SummarySpec.ModelSpec(
version="stable"
),
use_semantic_chunks=True,
)
extractive_content_spec = (
SearchRequest.ContentSearchSpec.ExtractiveContentSpec(
max_extractive_answer_count=5,
return_extractive_segment_score=False,
num_previous_segments=2,
num_next_segments=2,
)
)
search_result_mode = SearchRequest.ContentSearchSpec.SearchResultMode(
SearchRequest.ContentSearchSpec.SearchResultMode.DOCUMENTS
)
content_search_spec = SearchRequest.ContentSearchSpec(
snippet_spec=snippet_spec,
summary_spec=summary_spec,
search_result_mode=search_result_mode,
)
relevance_score_spec = SearchRequest.RelevanceScoreSpec(
return_relevance_score=True
)
request_params = {
"serving_config": SERVING_CONFIG,
"query": query,
"content_search_spec": content_search_spec,
"relevance_threshold": SearchRequest.RelevanceThreshold.LOW,
"relevance_score_spec": relevance_score_spec,
}
request = SearchRequest(**request_params)
response = search_client.search(request)
We’d appreciate any guidance and assistance.
Thanks in advance.