Skip to content

yuku/delete-rag-corpus-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delete RAG Corpus File

delete-rag-corpus-file is a simple Cloud Run function that deletes a corpus file from the VetexAI RAG Engine.

Required environment variables

Variable Description
PROJECT_ID GCP project ID
RAG_LOCATION Vertex AI RAG Engine location (e.g. us-central1)
RAG_CORPUS_ID RAG Corpus resource ID
RAG_FILE_INDEX_CACHE_GCS_PATH GCS path for the internal cache (inverted index) of corpus files.
Example: gs://your-bucket/rag_file_index.json.

Deployment

Clone this repository and deploy it to Cloud Run functions. Example:

FUNCTION_NAME=delete-rag-corpus-file
REGION=asia-northeast1
PROJECT_ID=$(gcloud config get-value project)
RAG_LOCATION=us-central1
RAG_CORPUS_ID=1111111111111111111
RAG_FILE_INDEX_CACHE_GCS_PATH=gs://your-bucket/rag_file_index.json

gcloud functions deploy "$FUNCTION_NAME" \
  --gen2 \
  --runtime=python312 \
  --region="$REGION" \
  --source=. \
  --entry-point=delete_rag_corpus_file \
  --trigger-http \
  --set-env-vars="PROJECT_ID=$PROJECT_ID,RAG_LOCATION=$RAG_LOCATION,RAG_CORPUS_ID=$RAG_CORPUS_ID,RAG_FILE_INDEX_CACHE_GCS_PATH=$RAG_FILE_INDEX_CACHE_GCS_PATH"

Concurrency and Race Conditions

This function uses an inverted index cache on GCS with optimistic concurrency control (via ifGenerationMatch) to avoid race conditions during updates. For most use cases, this mechanism is sufficient, even if the function is triggered by multiple clients at the same time.

If you expect frequent concurrent requests or want to guarantee strict serialization, you can combine this function with Cloud Tasks and set max-concurrent-dispatches=1 for your queue. This will ensure only one request is processed at a time and prevent even temporary conflicts.

Usage

FUNCTION_URL=$(gcloud functions describe "$FUNCTION_NAME" --region="$REGION" --format="value(url)")
ACCESS_TOKEN=$(gcloud auth print-identity-token)
curl -X POST "$FUNCTION_URL" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"gcs_source": {"uris": ["gs://backet/path/to/file"]}}'

About

delete-rag-corpus-file is a simple Cloud Run function that deletes a corpus file from the VetexAI RAG Engine

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages