Hi. Using AzureOpenAI (client = AzureOpenAI())
I can query my vector store and I can upload files, but the files don't seem to actually associate with the vector store when I load the Azure AI Foundry/ check it in the assistant vector stores section.
I don't get an error, it's just that the files don't seem to be attached. Any idea if this is a bug?
This works:
`
Retrieve files from the vector store.
def get_vector_store_files(vector_store_id, limit=100): file_data = [] after = None
while True:
try:
logging.info(f"Attempting to fetch vector store files for {vector_store_id} with after={after}")
response = client.vector_stores.files.list(vector_store_id, limit=limit, after=after)
except Exception as e:
logging.error(f"Error fetching vector store files: {e}")
break
for file in response.data:
try:
file_detail = client.files.retrieve(file.id)
upload_time = datetime.fromtimestamp(file_detail.created_at)
vs_filename = file_detail.filename
file_key = vs_filename[-16:] # use last 16 characters for matching
file_data.append({
"VectorStoreFileName": vs_filename,
"FileKey": file_key,
"VectorStoreUpload": upload_time,
"VectorStoreFileID": file_detail.id
})
logging.info(f"Retrieved vector store file: {vs_filename}")
except Exception as e:
logging.error(f"Error retrieving details for file ID {file.id}: {e}")
if getattr(response, 'has_more', False):
after = response.data[-1].id
else:
break
return file_data`
this works too, but not putting the files on the VS itself.
`
def upload_file_to_vector_store(vector_store_id, file_path): try: with open(file_path, "rb") as f: # Use the file batch helper to upload and attach the file. file_batch = client.vector_stores.file_batches.upload_and_poll( vector_store_id=vector_store_id, files=[f] ) logging.info(f"File batch upload status: {file_batch.status}") logging.info(f"File batch counts: {file_batch.file_counts}") return file_batch except Exception as e: logging.error(f"Error uploading file '{file_path}' to vector store: {e}")
def fix_any_upload_issues(vector_store_id): """ Checks the vector store for files with a status of 'failed' and attempts to reattach them. Retries up to 5 times per file. """ try: files_page = client.vector_stores.files.list(vector_store_id) files = files_page.data except Exception as e: logging.error(f"Error listing files from vector store {vector_store_id}: {e}") return
# Filter files that have a 'failed' status.
failed_files = [f for f in files if getattr(f, "status", None) == "failed"]
logging.info(f"Initial failed files: {[f.id for f in failed_files]}")
for failed_file in failed_files:
attempt = 0
success = False
while attempt < 5 and not success:
attempt += 1
logging.info(f"Attempt {attempt} for file {failed_file.id}")
try:
# Attempt to reattach the failed file to the vector store.
# Note: Using the create() method here. Depending on your SDK version,
# you might need to call client.vector_stores.files.create(...)
client.vector_stores.files.create(
vector_store_id, file_id=failed_file.id
)
# After the attempt, re-read the file list and check if this file still fails.
updated_files_page = client.vector_stores.files.list(vector_store_id)
updated_files = updated_files_page.data
updated_failed_files = [
f for f in updated_files if getattr(f, "status", None) == "failed"
]
if not any(f.id == failed_file.id for f in updated_failed_files):
success = True
logging.info(f"Successfully reattached file {failed_file.id}")
else:
logging.info(f"File {failed_file.id} still in failed status after attempt {attempt}")
except Exception as error:
logging.error(
f"Failed to reattach file {failed_file.id} on attempt {attempt}: {error}"
)
logging.info("Finished processing failed files.")`