예제 #1
0
def import_to_pg(table_name,ids,answer_file):
    conn = pg_operating.connect_postgres_server(PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, PG_DATABASE)
    cur = conn.cursor()
    pg_operating.create_pg_table(conn, cur, table_name)
    pg_operating.record_txt(ids,answer_file)
    pg_operating.copy_data_to_pg(conn, cur, table_name)
    pg_operating.build_pg_index(conn, cur, table_name)
예제 #2
0
def load_data(fname_path, client, conn, cursor, bc):
    try:
        question_data, answer_data = read_csv_data(fname_path)
    except Exception as e:
        print("read data faild: ", e)
        return False, "Failed to read data, please check the data file format."
    try:
        init_table(DEFAULT_TABLE, client, conn, cursor)
        question_vec = bc.encode(question_data)
        question_vec = normaliz_vec(question_vec)
        status, ids = milvus_insert(DEFAULT_TABLE, client, question_vec)
        record_temp_txt(fname_path, ids, answer_data, question_data)
        copy_data_to_pg(DEFAULT_TABLE, fname_path, conn, cursor)
        return True, "The data is loaded successfully."
    except Exception as e:
        print("load data faild: ", e)
        return False, "Failed to load data."