First commit
This commit is contained in:
42
scripts/test_rerank.py
Normal file
42
scripts/test_rerank.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from google.cloud import discoveryengine_v1 as discoveryengine
|
||||
|
||||
# TODO(developer): Uncomment these variables before running the sample.
|
||||
project_id = "bnt-orquestador-cognitivo-dev"
|
||||
|
||||
client = discoveryengine.RankServiceClient()
|
||||
|
||||
# The full resource name of the ranking config.
|
||||
# Format: projects/{project_id}/locations/{location}/rankingConfigs/default_ranking_config
|
||||
ranking_config = client.ranking_config_path(
|
||||
project=project_id,
|
||||
location="global",
|
||||
ranking_config="default_ranking_config",
|
||||
)
|
||||
request = discoveryengine.RankRequest(
|
||||
ranking_config=ranking_config,
|
||||
model="semantic-ranker-default@latest",
|
||||
top_n=10,
|
||||
query="What is Google Gemini?",
|
||||
records=[
|
||||
discoveryengine.RankingRecord(
|
||||
id="1",
|
||||
title="Gemini",
|
||||
content="The Gemini zodiac symbol often depicts two figures standing side-by-side.",
|
||||
),
|
||||
discoveryengine.RankingRecord(
|
||||
id="2",
|
||||
title="Gemini",
|
||||
content="Gemini is a cutting edge large language model created by Google.",
|
||||
),
|
||||
discoveryengine.RankingRecord(
|
||||
id="3",
|
||||
title="Gemini Constellation",
|
||||
content="Gemini is a constellation that can be seen in the night sky.",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
response = client.rank(request=request)
|
||||
|
||||
# Handle the response
|
||||
print(response)
|
||||
Reference in New Issue
Block a user