You can query data from a table by using an SDK or on the Query Test page in the OpenSearch Vector Search Edition console.
1. Configure the public access whitelist
If you access an OpenSearch Vector Search Edition instance from the virtual private cloud (VPC) in which the instance resides by using the same vSwitch, skip this step.
For more information about how to access an OpenSearch Vector Search Edition instance from an on-premises environment or the Internet, see Configure the public access whitelist.
2. Query data in a table
Use an SDK
The following sample code provides an example on how to use SDK for Python to query data in a table.
Add dependencies:
pip install alibabacloud-ha3engine-vector
Demo code for querying data:
from alibabacloud_ha3engine_vector.client import Client
from alibabacloud_ha3engine_vector.models import Config
from alibabacloud_ha3engine_vector.models import QueryRequest
config = Config(
# For private network calls, use the private endpoint.
endpoint="<your_api_endpoint>",
# The instance ID. You can find this in the upper-left corner of the instance details page. Example: ha-cn-i7*****605
instance_id="<your_instance_id>",
# The username. Find it in the Network Information section of the instance details page.
access_user_name="<your_username>",
# The password. You can change it in the Network Information section of the instance details page.
access_pass_word="<your_password>")
client = Client(config)
request = QueryRequest(table_name="<your_table_name>",
vector=[0.1, 0.2, 0.3],
include_vector=True,
top_k=10)
result = client.query(request)
print(result.body)
For more information about SDKs for other programming languages, see Query data.
If you use SDK for Python, you must remove the http:// prefix when you specify the endpoint parameter.
Sample response:
{
"totalCount": 1,
"result": [
{
"id": "1",
"vector": [
0.0019676426891237499,
...
],
"score": 0.0
}
],
"totalTime": 2.688
}
Use the OpenSearch console
-
In the OpenSearch Vector Search Edition console, click Instances in the left-side navigation pane. Find the target instance and click Query Test in the Actions column.
-
On the Query Test page, select the target index table.
Select the vector query tab. From the table name drop-down list, select the target index table, such as fengxue. In the JSON input area on the left, enter the query and click Search. The query results and elapsed time appear on the right.
Example:
{
"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
}
Sample response:
[
{
"vector": [
0.0019676426891237497,
0.0059029278345406055,
...
],
"id": "0",
"score": 0
}
]
Relevant query syntax: