An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
How do I delete all records where my date_ymd column in Azure Search Index is equal to a specific date?
Hi, I have an issue where I'm collecting a lot of data on a scheduled script that will store the data in a the Azure Search Index as a vector db and I then use RAG to collect data from this based on a prompt sent by a user in a chatbot and the AI's response is based on the top N documents from the storage.
My first question is if there's a way to workaround just using the top N documents from Azure Search Index. I get the top 50 documents for a users prompt and feed it to my chatbot's system prompt. Is there anyway to link my streamlit chatbot to the Azure Search Index directly without feeding only N documents.
Secondly and more importantly. I need the code to delete all documents for specific date_ymd values. Keep in mind all my columns and keys are string type and not date type. So Can you help with creating the script to delete values which have a certain string date.
This is my code for uploading documents:
def chunk_data(data, chunk_size):
for i in range(0, len(data), chunk_size):
yield data[i:i + chunk_size]
def upload_documents_to_search_client(df, embeddings_dict, chunk_size=32000):
"""Uploads documents with embeddings to the search client in chunks."""
data = [
{
"@search.action": "mergeOrUpload",
"hardware_id": str(row["hardware_id"]),
"text_feedback": str(row["text_feedback"]) if "text_feedback" in row else "",
"uninstall_text_feedback": str(row["uninstall_text_feedback"]) if "uninstall_text_feedback" in row else "",
"os": str(row["os"]) if "os" in row else "",
"date_ymd": str(row["date_ymd"]) if "date_ymd" in row else "",
"Feature_Category": str(row["Feature_Category"]) if "Feature_Category" in row else "",
"Sentiment": str(row["Sentiment"]) if "Sentiment" in row else "",
"country": str(row["country"]) if "country" in row else "",
"aiid": str(map_aiid_to_label(row["aiid"])) if "aiid" in row else "",
"version_app": str(row["version_app"]) if "version_app" in row else "",
"os_version": str(row["version"]) if "version" in row else "",
"architecture": str(row["architecture"]) if "architecture" in row else "",
"score": str(row["score"]) if "score" in row else "",
"region": str(row["region"]) if "region" in row else "",
"city": str(row["city"]) if "city" in row else "",
"vector_text_feedback": next(
(item["embeddings"].get("vector_text_feedback", []) for item in embeddings_dict if item["hardware_id"] == str(row["hardware_id"])),
[]
),
"vector_uninstall_feedback": next(
(item["embeddings"].get("vector_uninstall_feedback", []) for item in embeddings_dict if item["hardware_id"] == str(row["hardware_id"])),
[]
)
}
for _, row in df.iterrows()
]
for chunk in chunk_data(data, chunk_size):
try:
result = search_client.upload_documents(documents=chunk)
print(f"Uploaded {len(chunk)} documents successfully.")
except Exception as e:
print(f"An error occurred during document upload: {e}")
return None
Azure AI Search
1 answer
Sort by: Most helpful
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
8 deleted comments
Comments have been turned off. Learn more