import pyarrow.parquet as pq METADATA_FILEPATH = 'path/to/your/metadata_file.parquet' EMBEDDINGS_FILEPATH = 'path/to/your/embeddings.dat' def read_embeddings(filepath): # Read the lines from the file with open(filepath, 'rb') as f: lines = f.readlines() embedding_dict = {} for index, line in enumerate(lines): line_as_list = line.split() # Decode the byte string to a regular string and convert to float float_list = [float(byte_string.decode('utf-8')) for byte_string in line_as_list] # Save the float list (embeddings) to the dictionary with the index as the key embedding_dict[index] = float_list return embedding_dict #Read the metadata file metadata_df = pq.read_table(METADATA_FILEPATH).to_pandas() ## How to reach embeddings - example for a specific row unique_id = '390U_535R_2021-08-21064631_69' # Get the row with the unique_id row = metadata_df.loc[metadata_df['unique_id'] == unique_id] # Get the values for 'data_row' and 'embedding_file' dat_row_value = row['dat_row'] # index of the row in the embedding file embedding_file_value = row['embedding_file'] # specific embedding file for the row # Read the embeddings in the embedding file embeddings = read_embeddings(EMBEDDINGS_FILEPATH) vector = embeddings[dat_row_value] print(f"Row: {row}, Dat Row: {dat_row_value}, Embedding File: {embedding_file_value}, Vector length: {len(vector)}") #print(f"Vector: {vector}")