全部產品
Search
文件中心

OpenSearch:查詢資料

更新時間:Jul 13, 2024

使用者可通過SDK或控制台查詢測試頁面查詢表中資料

1、配置公網白名單

如果使用者的訪問環境是同個虛擬交換的VPC環境,可以忽略此步驟。

本地環境或公網環境請參考公網白名單配置

2、查詢表資料

SDK查詢

這裡以Python為例:

添加依賴

pip install alibabacloud-ha3engine-vector

查詢資料demo:

from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config
from alibabacloud_ha3engine_vector.models import QueryRequest

config = Config(
        #  私網網域名稱調用請填寫endpoint
        endpoint="<API網域名稱>",
        #  執行個體名稱,可在執行個體詳情頁左上方查看,例:ha-cn-i7*****605
        instance_id="<執行個體id>",
        #  使用者名稱,可在執行個體詳情頁>網路資訊 查看
        access_user_name="<使用者名稱>",
        #  密碼,可在執行個體詳情頁>網路資訊 修改
        access_pass_word="<使用者名稱密碼>")
client = Client(config)

request = QueryRequest(table_name="<表名>",
                    	vector=[0.1, 0.2, 0.3],
                        include_vector=True,
                        top_k=10)
result = client.query(request)
print(result.body)

其他查詢SDK可參考查詢資料

說明
  • Python SDK中endpoint裡需要去掉http://

相應結果樣本

{
    "totalCount": 1,
    "result": [
        {
            "id": "1",
            "vector": [
                0.0019676426891237499,
               ...
            ],
            "score": 0.0
        }
    ],
    "totalTime": 2.688
}

控制台查詢

  1. 在向量檢索版控制台>【執行個體管理】>【查詢測試】頁面:image.png

  1. 在查詢測試頁面選擇對應的索引表進行查詢:

image.png

樣本

{
  "vector": [0.0019676427,0.005902928,0.021644069,0.21644068,0.12199384,0.043288138,0.007870571,0.0,0.08460863,0.041320495,0.043288138,0.035417568,0.011805856,0.055093993,0.12592913,0.017708784,0.021644069,0.0019676427,0.0,0.0,0.0019676427,0.078705706,0.1987319,0.041320495,0.039352853,0.0039352854,0.007870571,0.0039352854,0.0039352854,0.017708784,0.035417568,0.06886749,0.0019676427,0.0019676427,0.013773498,0.049191065,0.2125054,0.22824654,0.123961486,0.0039352854,0.0,0.0,0.021644069,0.14560555,0.078705706,0.1987319,0.22824654,0.005902928,0.064932205,0.0019676427,0.0019676427,0.021644069,0.027546996,0.035417568,0.22824654,0.22824654,0.1337997,0.023611711,0.009838213,0.007870571,0.0039352854,0.0039352854,0.017708784,0.20069954,0.033449925,0.005902928,0.019676426,0.035417568,0.015741142,0.029514639,0.13183205,0.123961486,0.029514639,0.0,0.027546996,0.22824654,0.15741141,0.0,0.0039352854,0.043288138,0.18889369,0.072802775,0.055093993,0.17315255,0.08460863,0.0019676427,0.007870571,0.035417568,0.22824654,0.10034977,0.009838213,0.021644069,0.062964566,0.027546996,0.015741142,0.04525578,0.086576276,0.033449925,0.023611711,0.017708784,0.0,0.0,0.03738521,0.072802775,0.16724962,0.035417568,0.031482283,0.20463483,0.043288138,0.011805856,0.0039352854,0.051158708,0.023611711,0.11412327,0.13183205,0.16134669,0.049191065,0.023611711,0.0039352854,0.0039352854,0.049191065,0.035417568,0.015741142,0.0039352854,0.03738521,0.08264099,0.094446845,0.021644069],
  "topK": 10,
  "includeVector": true
}

相應結果

[
  {
    "vector": [
      0.0019676426891237497,
      0.0059029278345406055,
   	...
    ],
    "id": "0",
    "score": 0
  }
]

相關查詢文法