Skip to content

Commit

Permalink
Update py sdk version (#336)
Browse files Browse the repository at this point in the history
* Change insert more values

* Add hello_infinity.py demo

* One thread benchmark

* Modify benchmark multithreading

* Update py sdk version
  • Loading branch information
loloxwg authored Dec 20, 2023
1 parent 631d8fc commit 067191c
Show file tree
Hide file tree
Showing 26 changed files with 307 additions and 949 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ benchmark/csv/csv_config.h
#python sdk
python/build
python/dist
python/infinity.egg-info
python/.idea
python/infinity_sdk.egg-info


sift_1m
Expand Down
113 changes: 21 additions & 92 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,106 +17,35 @@ sudo apt-get install thrift-compiler
# build

```shell
python setup.py bdist_wheel
python setup.py sdist bdist_wheel
```

# install
```shell
pip install dist/infinity-0.0.1-py3-none-any.whl
pip install dist/*.whl
```

# upload
twine upload dist/*
# using

```python
import infinity
from infinity import NetworkAddress

infinity_obj = infinity.connect(NetworkAddress('127.0.0.1', 23817))

# infinity
res = infinity_obj.create_database("my_db")

res = infinity_obj.list_databases()

res = infinity_obj.drop_database("my_db")

db_obj = infinity_obj.get_database("default")
res = db_obj.create_table("my_table1", {"c1": "int, primary key"}, None)

res = db_obj.list_tables()

res = db_obj.drop_table("my_table1")

# index
res = db_obj.create_table("my_table2", {"c1": "vector,1024,float"}, None)

table_obj = db_obj.get_table("my_table2")

res = table_obj.create_index("my_index",
[index.IndexInfo("c1",
index.IndexType.IVFFlat,
[index.InitParameter("centroids_count", "128"),
index.InitParameter("metric", "l2")])], None)

res = table_obj.drop_index("my_index")

res = db_obj.drop_table("my_table2")

# insert
res = db_obj.create_table("my_table3", {"c1": "int, primary key", "c2": "float"}, None)

table_obj = db_obj.get_table("my_table3")

res = table_obj.insert([{"c1": 1, "c2": 1.1}, {"c1": 2, "c2": 2.2}])

res = db_obj.create_table("test_insert_varchar", {"c1": "varchar"}, None)

table_obj = db_obj.get_table("test_insert_varchar")

res = table_obj.insert([{"c1": "test_insert_varchar"}])

res = db_obj.create_table("test_insert_embedding", {"c1": "vector,3,int"}, None)

table_obj = db_obj.get_table("test_insert_embedding")

res = table_obj.insert([{"c1": [4, 5, 6]}])

res = table_obj.insert([{"c1": [1, 2, 3]}, {"c1": [4, 5, 6]}, {"c1": [7, 8, 9]}, {"c1": [-7, -8, -9]}])

# search

res = table_obj.search().output(["c1 + 0.1"]).to_df()

res = table_obj.search().output(["*"]).filter("c1 > 1").to_df()

# import
res = db_obj.create_table("my_table4", {"c1": "int", "c2": "vector,3,int"}, None)
table_obj = db_obj.get_table("my_table4")
parent_dir = os.path.dirname(os.path.dirname(os.getcwd()))
test_csv_dir = parent_dir + "/test/data/csv/embedding_int_dim3.csv"

res = table_obj.import_data(test_csv_dir, None)

# search
res = table_obj.search().output(["c1"]).filter("c1 > 1").to_df()

res = db_obj.drop_table("my_table4")


res = db_obj.create_table("table_4", {"c1": "int, primary key, not null", "c2": "int", "c3": "int"}, None)

table_obj = db_obj.get_table("table_4")

res = table_obj.insert(
[{"c1": 1, "c2": 10, "c3": 100}, {"c1": 2, "c2": 20, "c3": 200}, {"c1": 3, "c2": 30, "c3": 300},
{"c1": 4, "c2": 40, "c3": 400}])

res = table_obj.update("c1 = 1", [{"c2": 90, "c3": 900}])

res = table_obj.delete("c1 = 1")

res = table_obj.delete()

# disconnect
res = infinity_obj.disconnect()
from infinity.common import REMOTE_HOST

infinity_obj = infinity.connect(REMOTE_HOST)
db = infinity_obj.get_database("default")
db.drop_table("my_table", if_exists=True)
table = db.create_table(
"my_table", {"num": "integer", "body": "varchar", "vec": "vector,5,float"}, None)
table.insert(
[{"num": 1, "body": "undesirable, unnecessary, and harmful", "vec": [1.0] * 5}])
table.insert(
[{"num": 2, "body": "publisher=US National Office for Harmful Algal Blooms", "vec": [4.0] * 5}])
table.insert(
[{"num": 3, "body": "in the case of plants, growth and chemical", "vec": [7.0] * 5}])

res = table.output(["*"]).knn("vec", [3.0] * 5, "float", "ip", 2).to_pl()
print(res)

```
Loading

0 comments on commit 067191c

Please sign in to comment.