-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable limit and offset expression of Python and HTTP API (#1905)
### What problem does this PR solve? 1. Fix limit and offset in Python API and HTTP API 2. Add an example to demonstrate how to use limit and offset in Python API. Issue link:#1903 #1896 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Signed-off-by: Jin Hai <[email protected]>
- Loading branch information
Showing
18 changed files
with
441 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright(C) 2023 InfiniFlow, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
''' | ||
This example is to connect local infinity instance, create table, insert data, search the data | ||
''' | ||
|
||
# import infinity_embedded as infinity | ||
import infinity | ||
import sys | ||
|
||
try: | ||
# Use infinity_embedded module to open a local directory | ||
# infinity_instance = infinity.connect("/var/infinity") | ||
|
||
# Use infinity module to connect a remote server | ||
infinity_instance = infinity.connect(infinity.common.NetworkAddress("127.0.0.1", 23817)) | ||
|
||
# 'default_db' is the default database | ||
db_instance = infinity_instance.get_database("default_db") | ||
|
||
# Drop my_table if it already exists | ||
db_instance.drop_table("my_table", infinity.common.ConflictType.Ignore) | ||
|
||
# Create a table named "my_table" | ||
table_instance = db_instance.create_table("my_table", { | ||
"num": {"type": "integer"}, | ||
"body": {"type": "varchar"}, | ||
"vec": {"type": "vector, 4, float"}, | ||
}) | ||
|
||
# Insert 3 rows of data into the 'my_table' | ||
table_instance.insert( | ||
[ | ||
{ | ||
"num": 1, | ||
"body": r"unnecessary and harmful", | ||
"vec": [1.0, 1.2, 0.8, 0.9], | ||
}, | ||
{ | ||
"num": 2, | ||
"body": r"Office for Harmful Blooms", | ||
"vec": [4.0, 4.2, 4.3, 4.5], | ||
}, | ||
{ | ||
"num": 3, | ||
"body": r"A Bloom filter is a space-efficient probabilistic data structure, conceived by Burton Howard Bloom in 1970, that is used to test whether an element is a member of a set.", | ||
"vec": [4.0, 4.2, 4.3, 4.2], | ||
}, | ||
] | ||
) | ||
|
||
result = table_instance.output(["num", "vec", "_similarity"]).match_dense("vec", [3.0, 2.8, 2.7, 3.1], "float", | ||
"cosine", 3).limit(2).offset(1).to_pl() | ||
print(result) | ||
infinity_instance.disconnect() | ||
|
||
print('test done') | ||
sys.exit(0) | ||
except Exception as e: | ||
print(str(e)) | ||
sys.exit(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.