Connects to the Infinity server and gets an Infinity object.
infinity_obj = infinity.connect(REMOTE_HOST)This method connect to the Infinity server and return a infinity object.
REMOTE_HOST = NetworkAddress("127.0.0.1", 9080)
- success: An Infinity object.
- failure:
Exception
Disconnects from the Infinity server.
infinity_obj.disconnect()This method disconnects the current Infinity object from the server.
It is automatically called when an Infinity object is destructed.
- success:
- response
successisTrue
- response
- failure:
Exception
Creates a database.
infinity_obj.create_database("my_database")This method creates a database by name.
db_name:str
- success:
- response
successisTrue
- response
- failure:
Exception
Drops a database.
infinity_obj.drop_database("my_database")This method drops a database by name.
db_name:strName of the database to drop.
- success:
- response
successisTrue
- response
- failure:
Exception
Lists all databases.
infinity_obj.list_databases()This method lists all databases.
- success:
- response
successisTrue. - response
db_nameslist[str]
- response
- failure:
Exception
Gets a database object.
db_obj=infinity_obj.get_database("default")This method retrieves a database object by name.
db_name:strThe name of the database to retrieve.
- success:
- A database object.
- failure:
Exception
Creates a table.
db_obj.create_table("test_create_varchar_table",
{"c1": "varchar, primary key", "c2": "float"}, None)
db_obj.create_table("test_create_embedding_table",
{"c1": "vector,128,float"}, None)columns_definition:dict- key:
column name:str - value: <
datatype>,<constraint>,<constraint> :str
- key:
columns_definition:dict- key:
column name:str - value: vector,<
dimension>,<element_type> :str
- key:
table_name:strcolumns_definition:dict[str, str]options: None
- success:
- response
successisTrue
- response
- failure:
Exception
Drops a table.
db_obj.drop_table("test_create_varchar_table", if_exists=True)Drops a table by name.
table_name:strThe name of the table to drop.if_exists:bool
- success:
- response
successisTrue
- response
- failure:
Exception
Gets a table object.
table_obj = db_obj.get_table("test_create_varchar_table")This method retrieves a table object by name.
table_name:strThe name of the intended table.
- success:
- A table object
- failure:
Exception
Lists all tables.
db_obj.list_tables()This method lists all tables in the database.
- success:
- response
successisTrue - response
table_nameslist[str]
- response
- failure:
Exception
Creates an index by IndexInfo list.
db_obj.create_table("test_index_ivfflat", {
"c1": "vector,1024,float"}, None)
db_obj.get_table("test_index_ivfflat")
table_obj.create_index("my_index",
[index.IndexInfo("c1",index.IndexType.IVFFlat,
[
index.InitParameter("centroids_count", "128"),
index.InitParameter("metric", "l2")
])], None)db_obj.create_table(
"test_index_hnsw", {"c1": "vector,1024,float"}, None)
db_obj.get_table("test_index_hnsw")
table_obj.create_index("my_index",
[index.IndexInfo("c1",index.IndexType.Hnsw,
[
index.InitParameter("M", "16"),
index.InitParameter("ef_construction", "50"),
index.InitParameter("ef", "50"),
index.InitParameter("metric", "l2")
])], None)db_obj.create_table(
"test_index_fulltext", {"doctitle": "varchar", "docdate": "varchar", "body": "varchar"}, None)
db_obj.get_table("test_index_fulltext")
table_obj.create_index("my_index",
[index.IndexInfo("body",
index.IndexType.IRSFullText,
[index.InitParameter("ANALYZER", "segmentation")]),
index.IndexInfo("doctitle",
index.IndexType.IRSFullText,
[]),
index.IndexInfo("docdate",
index.IndexType.IRSFullText,
[]),
], None)This method uses indexInfo to create an index.
IndexInfocolumn_name:strName of the column. Required.index_type:Enum. The index type. Includes:IVFFlatHnswLVQ- ``Hnsw`
IRSFullText
index_param_list: list[InitParameter]param_name:strparam_value:str- example
InitParameter("M", "16")InitParameter("ef_construction", "50")InitParameter("ef", "50")InitParameter("metric", "l2")InitParameter("centroids_count", "128")
index_name:strindex_infos:list[IndexInfo]options: None
- success:
- response
successisTrue
- response
- failure:
Exception
Drops an index.
table_obj.drop_index("my_index")This method drops an index by index name.
index_name:strThe name of the index to drop.
- success:
- response
successisTrue
- response
- failure:
Exception
Inserts a record into the table.
table_obj.insert([{"profile": [1.1, 2.2, 3.3], "age": 30, "c3": "Michael"}])table_obj.insert([{"c1": [1.1, 2.2, 3.3]}])This method inserts a record into a table. The inserted record is a list of dict.
dict- key:
column name:str - value:
str,int,float,list
- key:
data: list[dict[str, Union[str, int, float, list[Union[int, float]]]]]
- success:
- response
successisTrue
- response
- failure:
Exception
Imports data into the table.
table_obj.import_data(test_csv_dir, None)This method imports data into the table object. Supported file types:
csvfvecsjson
file_path: stroptions:None
- success:
- response
successisTrue
- response
- failure:
Exception
Delete rows by condition.
table_obj.delete("c1 = 1")
table_obj.delete()The condition is similar to the WHERE conditions in SQL. If condition is not specified, this method deletes all data in the table object.
cond: Optional[str]options: None
- success:
- response
successisTrue
- response
- failure:
Exception
Updates rows by condition.
table_obj.update("c1 = 1", [{"c2": 90, "c3": 900}])This method searches for rows that satisfy the search condition and updates them using the provided values.
- The search condition is similar to the WHERE conditions in SQL.
- Data is what needs to be updated.
cond:strdata: list[dict[str, Union[str, int, float]]]
- success:
- response
successisTrue
- response
- failure:
Exception
Gets a query_builder by self.
query_builder=table_obj.query_builder()This method retrieves a query_builder by self table.
- success:
- A
query_builderobject.
- A
- failure:
Exception
Specifies the columns to display in the search output.
query_builder.output(["num", "body"])
# To display all columns
query_builder.output(["*"])
# To display row ID
query_builder.output(["_row_id"])This method specifies the columns to display in the search output. You must input a list of str
- To display all columns:
["*"] - To display row ID:
["_row_id"]
columns: Optional[list[str]]
- self :
InfinityThriftQueryBuilder
Builds a filtering condition expression.
query_builder.filter("(-7 < c1 or 9 >= c1) and (c2 = 3)")This method builds a filtering expression.
str: Similar to the WHERE condition in SQL.
where: Optional[str]
- self :
InfinityThriftQueryBuilder
Builds a KNN search expression.
query_builder.knn('col1', [0.1,0.2,0.3], 'float', 'l2', 100)
query_builder.knn('vec', [3.0] * 5, 'float', 'ip', 2)VEC supports list or np.ndarray.
-
vector_column_name:str -
embedding_data: VEC -
embedding_data_type: `str``floatint
-
distance_type:strl2cosineiphamming
-
topn:int
- self :
InfinityThriftQueryBuilder
Builds a full-text search expression.
query_builder.match('body', 'harmful', 'topn=2')This method builds a full-text search expression.
fields:strThe text’s bodymatching_text:strThe text to match.options_text:str'topn=2': The display count is 2.
- self :
InfinityThriftQueryBuilder
Builds a fusion expression.
query_builder.fusion('rrf')rrf: Reciprocal rank fusion method.
Reciprocal rank fusion (RRF) is a method that combines multiple result sets with different relevance indicators into one result set. RRF does not requires tuning, and the different relevance indicators do not have to be related to each other to achieve high-quality results.
method:str
- self :
InfinityThriftQueryBuilder
Returns a data result.
table_obj.query_builder().output(["*"]).to_result()This method returns a data result of Python's built-in type.
(data_dict, data_type_dict)
tuple[dict[str, list[Any]], dict[str, Any]]
Returns a pandas result.
table_obj.query_builder().output(["*"]).to_df()This method returns a data result in pandas DataFrame.
pandas.DataFrame
Returns a polars result.
table_obj.query_builder().output(["*"]).to_pl()This method returns a data result in polars DataFrame
polars.DataFrame
Returns a pyarrow result.
table_obj.query_builder().output(["*"]).to_arrow()The method returns a data result in arrow Table.
- pyarrow.
Table