import io
# Path to your local CSV file
csv_file_path = '../../data/vector_database_wikipedia_articles_embedded.csv'
# Define a generator function to process the csv file
def process_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
yield line
# Create a StringIO object to store the modified lines
modified_lines = io.StringIO(''.join(list(process_file(csv_file_path))))
# Create the COPY command for copy_expert
copy_command = '''
COPY public.articles (id, url, title, content, title_vector, content_vector, vector_id)
FROM STDIN WITH (FORMAT CSV, HEADER true, DELIMITER ',');
'''
# Execute the COPY command using copy_expert
cursor.copy_expert(copy_command, modified_lines)
# Commit the changes
connection.commit()