通過SDK 調用向量檢索版實例進行數據檢索
通用代碼示例
from alibabacloud_ha3engine import models, client
from Tea.exceptions import TeaException, RetryError
import json
Config = models.Config(
endpoint="ha-cn-***********.public.ha.aliyuncs.com",
instance_id="ha-cn-***********",
protocol="http",
access_user_name="username",
access_pass_word="passsword"
)
# 初始化 Ha3Engine Client
ha3EngineClient = client.Client(Config)
def search():
try:
# 構造rest查詢條件,具體查詢語法請參考:http://bestwisewords.com/document_detail/2247524.html?spm=a2c4g.2247608.0.0.4eeb2393PCewr2
data = {"query": "index_id: 1", "config": {"format": "json"}}
json_str = json.dumps(data)
# 構造SearchRequestModel查詢對象
searchRequestModel = models.SearchRequestModel(body=json_str)
# 替換{indexName}為待查詢實例的索引表名
responseModel = ha3EngineClient.search_rest(request=searchRequestModel, index_name="{indexName}")
print(responseModel.body)
except TeaException as e:
print(f"send request with TeaException : {e}")
except RetryError as e:
print(f"send request with Connection Exception : {e}")
search()
文檔內容是否對您有幫助?