Insert text and embeddings into vector store
In this notebook, the wikipedia articles dataset provided by OpenAI, the embeddings are pre-computed. The code below takes the data frame and converts it into a dictionary list to upload to your Azure Search index.

# Convert the 'id' and 'vector_id' columns to string so one of them can serve as our key field
article_df['id'] = article_df['id'].astype(str)
article_df['vector_id'] = article_df['vector_id'].astype(str)

# Convert the DataFrame to a list of dictionaries
documents = article_df.to_dict(orient='records')

search_client = SearchClient(endpoint=search_service_endpoint, index_name=index_name, credential=credential)

# Define the batch upload size
batch_size = 250

# Split the documents into batches
batches = [documents[i:i + batch_size] for i in range(0, len(documents), batch_size)]

# Upload each batch of documents
for batch in batches:
    result = search_client.upload_documents(batch)

print(f"Uploaded {len(documents)} documents in total")