import json import infinity import infinity.index as index from infinity.common import REMOTE_HOST import pandas as pds def main(): try: infinity_obj = infinity.connect(REMOTE_HOST) db = infinity_obj.get_database("default") db.drop_table("fnclass_table", if_exists=True) # Create "fnclass_table" class_table = db.create_table("fnclass_table", {"id": "varchar","vec": "vector, 4, float", "body": "varchar", "req": "varchar", "keyid": "varchar"}, None) class_table.insert([{"id": 4, "vec": [-0.014, 0.008, 0.021, -0.003], "body": "Zumba", "keyid": "202308080000721", "req": ""}]) class_table.insert([{"id": 82, "vec": [-0.007, -0.007, -0.024, 0.031], "body": "yoga", "keyid": "202309020000121", "req": ""}]) class_table.insert([{"id": 17, "vec": [0.023, 0.064, -0.030, 0.107], "body": "aerobics", "keyid": "202308080000721", "req": ""}]) # `create_index()` is required before match() or fusion() tblidx = class_table.create_index("cls_index", [index.IndexInfo("body", index.IndexType.FullText, [index.InitParameter("ANALYZER", "segmentation")]), ], None) #test text search - got result qb_result = class_table.match( "body", "zumba", "topn=1").fusion("rrf").output(["body","req"]).to_pl() print("------tabular - full txt search-------") print(qb_result) #test text search - empty result qb_result = class_table.match( "id", "17", "topn=1").fusion("rrf").output(["body","req"]).to_pl() print("------tabular - full txt search-------") print(qb_result) #created new table and tried text search but did not get result as expected. db.drop_table("t_class_intents", if_exists=True) # Create "t_class_intents" intent_tble = db.create_table("t_class_intents", {"intent_id": "varchar", "intent_name":"varchar", "body":"varchar", "int_vec": "vector, 4, float", "neuron_id": "varchar", "neuron_name": "varchar", "data_txt": "varchar"}, None) # index creation residxs = intent_tble.create_index("class_intent_index", [index.IndexInfo("body", index.IndexType.FullText, [index.InitParameter("ANALYZER", "segmentation")]), ], None) residx1s = intent_tble.create_index("class_neuron_index", [index.IndexInfo("neuron_name", index.IndexType.FullText, []), ], None) intent_tble.insert([{"intent_id": 1, "int_vec": [-0.056, 0.018, -0.064, 0.010], "intent_name": "add_class", "body":"add_class", "neuron_id": "111", "neuron_name": "add_class", "data_txt":""}]) intent_tble.insert([{"intent_id": 2, "int_vec": [-0.076, 0.067, -0.055, 0.060], "intent_name": "edit_class", "body":"edit_class", "neuron_id": "112", "neuron_name": "edit_class", "data_txt":""}]) intent_tble.insert([{"intent_id": 2, "int_vec": [-0.076, 0.067, -0.055, 0.060], "intent_name": "edit_class", "body":"edit_class", "neuron_id": "113", "neuron_name": "modify_class", "data_txt":""}]) intent_tble.insert([{"intent_id": 2, "int_vec": [-0.076, 0.067, -0.055, 0.060], "intent_name": "edit_class", "body":"edit_class", "neuron_id": "114", "neuron_name": "change_class", "data_txt":""}]) intent_tble.insert([{"intent_id": 3, "int_vec": [-0.051, -0.004, -0.085, -0.020], "intent_name": "view_class", "body":"view_class", "neuron_id": "115", "neuron_name": "view_class", "data_txt":""}]) intent_tble.insert([{"intent_id": 3, "int_vec": [-0.051, -0.004, -0.085, -0.020], "intent_name": "view_class", "body":"view_class", "neuron_id": "116", "neuron_name": "list_class", "data_txt":""}]) intent_tble.insert([{"intent_id": 4, "int_vec": [-0.051, 0.082, -0.054, -0.026], "intent_name": "delete_class", "body":"delete_class", "neuron_id": "223", "neuron_name": "delete_class", "data_txt":""}]) temp_result = intent_tble.match("body","add_class", "topn=1").fusion("rrf").output(["neuron_name"]).to_pl() print(temp_result) #no result intent_qb = intent_tble.query_builder qb_output = intent_qb.match("body","add_class","topn=1").output(["*"]).to_pl() print(qb_output) #no result intent_name_val = 'add_class' qb_output = intent_qb.filter(f"intent_name='{intent_name_val}'").output(["*"]).to_pl() print(qb_output) #got result except Exception as e: print(str(e)) if __name__ == '__main__': main()