def read_csv_data()

in 11-recommendation/upload-to-qdrant.py [0:0]


def read_csv_data(csv_file_path: str) -> List[Dict[str, Any]]:
    """
    Reads data from a CSV file and returns a list of dictionaries.
    """
    data_entries = []
    try:
        with open(csv_file_path, mode='r', encoding='utf-8') as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                # Convert data types as necessary
                row['price'] = float(row['price']) if row['price'] else None
                embedding_str = row.get('embedded_description')
                if embedding_str:
                    try:
                        row['embedded_description'] = ast.literal_eval(embedding_str)
                        if not isinstance(row['embedded_description'], list):
                            logger.error(f"Embedding for row {row} is not a list.")
                            row['embedded_description'] = []
                    except (ValueError, SyntaxError) as e:
                        logger.error(f"Error parsing embedding for row {row}: {e}")
                        row['embedded_description'] = []
                else:
                    row['embedded_description'] = []
                
                data_entries.append(row)
        logger.info(f"Read {len(data_entries)} entries from {csv_file_path}")
    except Exception as e:
        logger.error(f"Error reading CSV file {csv_file_path}: {e}")
    return data_entries