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", 23817)
- 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
success
isTrue
- response
- failure:
Exception
Creates a database.
infinity_obj.create_database("my_database")
This method creates a database by name.
db_name
:str
- success:
- response
success
isTrue
- response
- failure:
Exception
Drops a database.
infinity_obj.drop_database("my_database")
This method drops a database by name.
db_name
:str
Name of the database to drop.
- success:
- response
success
isTrue
- response
- failure:
Exception
Lists all databases.
infinity_obj.list_databases()
This method lists all databases.
- success:
- response
success
isTrue
. - response
db_names
list[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
:str
The 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
:str
columns_definition
:dict[str, str]
options
: None
- success:
- response
success
isTrue
- response
- failure:
Exception
Drops a table.
db_obj.drop_table("test_create_varchar_table", if_exists=True)
Drops a table by name.
table_name
:str
The name of the table to drop.if_exists
:bool
- success:
- response
success
isTrue
- 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
:str
The 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
success
isTrue
- response
table_names
list[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.FullText,
[index.InitParameter("ANALYZER", "segmentation")]),
index.IndexInfo("doctitle",
index.IndexType.FullText,
[]),
index.IndexInfo("docdate",
index.IndexType.FullText,
[]),
], None)
This method uses indexInfo
to create an index.
IndexInfo
column_name
:str
Name of the column. Required.index_type
:Enum
. The index type. Includes:IVFFlat
HnswLVQ
Hnsw
FullText
index_param_list
: list[InitParameter]param_name
:str
param_value
:str
- example
InitParameter("M", "16")
InitParameter("ef_construction", "50")
InitParameter("ef", "50")
InitParameter("metric", "l2")
InitParameter("centroids_count", "128")
index_name
:str
index_infos
:list[IndexInfo]
options
: None
- success:
- response
success
isTrue
- response
- failure:
Exception
Drops an index.
table_obj.drop_index("my_index")
This method drops an index by index name.
index_name
:str
The name of the index to drop.
- success:
- response
success
isTrue
- 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
success
isTrue
- 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:
csv
fvecs
json
file_path
: stroptions
:None
- success:
- response
success
isTrue
- 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
success
isTrue
- 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
:str
data
: list[dict[str, Union[str, int, float]]]
- success:
- response
success
isTrue
- response
- failure:
Exception
Specifies the columns to display in the search output.
table_obj.output(["num", "body"])
# To display all columns
table_obj.output(["*"])
# To display row ID
table_obj.output(["_row_id"])
Convert output to different display types.
# Returns a data result
table_obj.output(["*"]).to_result()
# Returns a pandas result
table_obj.output(["*"]).to_df()
# Returns a polars result
table_obj.output(["*"]).to_pl()
# Returns a pyarrow result
table_obj.output(["*"]).to_arrow()
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.
table_obj.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.
table_obj.knn('col1', [0.1,0.2,0.3], 'float', 'l2', 100)
table_obj.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
float
int
-
distance_type
:str
l2
cosine
ip
hamming
-
topn
:int
- self :
InfinityThriftQueryBuilder
Builds a full-text search expression.
table_obj.match('body', 'harmful', 'topn=2')
This method builds a full-text search expression.
fields
:str
The text’s bodymatching_text
:str
The text to match.options_text
:str
'topn=2'
: The display count is 2.
- self :
InfinityThriftQueryBuilder
Builds a fusion expression.
table_obj.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.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.output(["*"]).to_df()
This method returns a data result in pandas DataFrame
.
pandas.DataFrame
Returns a polars result.
table_obj.output(["*"]).to_pl()
This method returns a data result in polars DataFrame
polars.DataFrame
Returns a pyarrow result.
table_obj.output(["*"]).to_arrow()
The method returns a data result in arrow Table
.
- pyarrow.
Table