Skip to content

Commit 5c06717

Browse files
authored
HTTP API: Search (infiniflow#870)
### What problem does this PR solve? 1. Filter, output, knn is OK. But output vector and match doens't work. 2. Fix hello_infinity.py Issue link:infiniflow#779 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
1 parent 82108cc commit 5c06717

File tree

8 files changed

+559
-77
lines changed

8 files changed

+559
-77
lines changed

docs/references/http_api_reference.md

+18-32
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,11 @@ curl --request PUT \
618618
--header 'content-type: application/json' \
619619
--data ' \
620620
{
621-
update:
621+
"update":
622622
{
623623
"score": 95
624624
},
625-
filter: "age > 15"
625+
"filter": "age > 15"
626626
} '
627627
```
628628

@@ -646,9 +646,9 @@ curl --request PUT \
646646
}
647647
```
648648

649-
## Select
649+
## Search
650650

651-
Selects data from a specified table.
651+
Search data from a specified table.
652652

653653
#### Request
654654

@@ -659,44 +659,30 @@ curl --request GET \
659659
--header 'content-type: application/json' \
660660
--data ' \
661661
{
662-
output:
662+
"output":
663663
[
664664
"name",
665665
"age"
666666
],
667-
filter: "age > 15",
668-
fusion:
667+
"filter": "age > 15",
668+
"fusion":
669669
{
670-
method: "rrf",
671-
match:
670+
"method": "rrf",
671+
"match":
672672
{
673-
"title":
674-
{
675-
"query": "rock fire",
676-
"operator": "and"
677-
}
673+
"fields": "title",
674+
"query": "rock fire",
675+
"operator": "and"
678676
}
679-
knn:
677+
"knn":
680678
{
681-
"vector_column":
682-
{
683-
"query_vector": [1.0, 2.0],
684-
"ef" : 150,
685-
"top_k": 3
686-
}
679+
"fields": "vector_column",
680+
"query_vector": [1.0, 2.0],
681+
"ef" : "150",
682+
"top_k": 3,
683+
"metric_type": L2
687684
}
688685
}
689-
knn:
690-
{
691-
vector:
692-
[
693-
0.1,
694-
0.2,
695-
0.3,
696-
0.4,
697-
],
698-
top: 1
699-
}
700686
} '
701687
```
702688

python/hello_infinity.py

+19-24
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,21 @@
1616
import infinity
1717
import infinity.index as index
1818
from infinity.common import REMOTE_HOST
19+
from infinity.common import ConflictType
1920
import pandas as pds
2021

2122

2223
def main():
2324
infinity_obj = infinity.connect(REMOTE_HOST)
2425
db = infinity_obj.get_database("default")
25-
db.drop_table("my_table", if_exists=True)
26-
table = db.create_table(
27-
"my_table", {"num": "integer", "body": "varchar", "vec": "vector,5,float"}, None)
28-
table.insert(
29-
[{"num": 1, "body": "undesirable, unnecessary, and harmful", "vec": [1.0] * 5}])
30-
table.insert(
31-
[{"num": 2, "body": "publisher=US National Office for Harmful Algal Blooms", "vec": [4.0] * 5}])
32-
table.insert(
33-
[{"num": 3, "body": "in the case of plants, growth and chemical", "vec": [7.0] * 5}])
34-
35-
res = table.output(["*"]).knn("vec", [3.0] * 5, "float", "ip", 2).to_pl()
26+
# Drop my_table if it already exists
27+
db.drop_table("my_table", ConflictType.Ignore)
28+
# Create a table named "my_table"
29+
table = db.create_table("my_table", {"num": "integer", "body": "varchar", "vec": "vector, 4, float"})
30+
table.insert([{"num": 1, "body": "unnecessary and harmful", "vec": [1.0, 1.2, 0.8, 0.9]}])
31+
table.insert([{"num": 2, "body": "Office for Harmful Blooms", "vec": [4.0, 4.2, 4.3, 4.5]}])
32+
33+
res = table.output(["*"]).knn("vec", [3.0, 2.8, 2.7, 3.1], "float", "ip", 2).to_pl()
3634
print(res)
3735

3836

@@ -41,21 +39,18 @@ def test():
4139
infinity_obj = infinity.connect(REMOTE_HOST)
4240
db = infinity_obj.get_database("default")
4341
# Drop my_table if it already exists
44-
db.drop_table("my_table", if_exists=True)
42+
db.drop_table("my_table", ConflictType.Ignore)
4543
# Create a table named "my_table"
46-
table = db.create_table("my_table", {
47-
"num": "integer", "body": "varchar", "vec": "vector, 4, float"}, None)
48-
table.insert(
49-
[{"num": 1, "body": "unnecessary and harmful", "vec": [1.0, 1.2, 0.8, 0.9]}])
50-
table.insert(
51-
[{"num": 2, "body": "Office for Harmful Blooms", "vec": [4.0, 4.2, 4.3, 4.5]}])
44+
table = db.create_table("my_table", {"num": "integer", "body": "varchar", "vec": "vector, 4, float"})
45+
table.insert([{"num": 1, "body": "unnecessary and harmful", "vec": [1.0, 1.2, 0.8, 0.9]}])
46+
table.insert([{"num": 2, "body": "Office for Harmful Blooms", "vec": [4.0, 4.2, 4.3, 4.5]}])
5247

5348
# `create_index()` is required before match() or fusion()
54-
# res = table.create_index("my_index",
55-
# [index.IndexInfo("body",
56-
# index.IndexType.FullText,
57-
# [index.InitParameter("ANALYZER", "segmentation")]),
58-
# ], None)
49+
res = table.create_index("my_index",
50+
[index.IndexInfo("body",
51+
index.IndexType.FullText,
52+
[index.InitParameter("ANALYZER", "segmentation")]),
53+
], ConflictType.Error)
5954
# assert res.success
6055

6156
res = table.output(["num", "body"]).knn(
@@ -97,5 +92,5 @@ def test():
9792

9893

9994
if __name__ == '__main__':
100-
# main()
95+
main()
10196
test()

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ add_executable(infinity
231231
${network_cpp}
232232
network/http_server.cppm
233233
network/http_server.cpp
234+
network/http/http_search.cppm
235+
network/http/http_search.cpp
234236
)
235237

236238
target_sources(infinity

0 commit comments

Comments
 (0)