fix: drop backend_config from create_corpus — rely on pre-flight PATCH alone
SDK 1.153.1 has a bug in set_backend_config where it calls .CopyFrom() on RagManagedDb which is not a real protobuf message. The project-level ragEngineConfig PATCH already sets basic tier, so passing backend_config is unnecessary and breaks corpus creation.
This commit is contained in:
parent
46b3c52607
commit
2beb6a359d
|
|
@ -3,12 +3,9 @@
|
||||||
setup_corpus.py — Create a Vertex AI RAG Engine corpus and import documents.
|
setup_corpus.py — Create a Vertex AI RAG Engine corpus and import documents.
|
||||||
Project: propane-will-491900-m5
|
Project: propane-will-491900-m5
|
||||||
|
|
||||||
Explicitly uses Serverless (RagManagedDb) to avoid Spanner allowlist
|
Serverless mode is controlled via the project-level ragEngineConfig PATCH
|
||||||
restrictions on new projects in us-central1.
|
(ensure_serverless_engine_config). Passing backend_config to create_corpus
|
||||||
|
triggers a SDK 1.153.1 bug and must be omitted.
|
||||||
Tested against vertexai SDK 1.153.1:
|
|
||||||
RagVectorDbConfig(vector_db=RagManagedDb())
|
|
||||||
RagManagedDb is a no-arg marker class — selecting it is sufficient for serverless.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
@ -31,7 +28,8 @@ GCS_SOURCE = os.environ.get(
|
||||||
def ensure_serverless_engine_config() -> None:
|
def ensure_serverless_engine_config() -> None:
|
||||||
"""
|
"""
|
||||||
Pre-flight: set project-level RAG Engine Config to basic (serverless) tier.
|
Pre-flight: set project-level RAG Engine Config to basic (serverless) tier.
|
||||||
Idempotent — safe to re-run.
|
This is what actually controls the backend — backend_config in create_corpus
|
||||||
|
is intentionally omitted due to SDK bug in 1.153.1.
|
||||||
"""
|
"""
|
||||||
print("Ensuring RAG Engine Config is set to serverless (basic) tier...")
|
print("Ensuring RAG Engine Config is set to serverless (basic) tier...")
|
||||||
endpoint = (
|
endpoint = (
|
||||||
|
|
@ -71,21 +69,17 @@ def ensure_serverless_engine_config() -> None:
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_corpus() -> RagCorpus:
|
def get_or_create_corpus() -> RagCorpus:
|
||||||
"""Return existing corpus by display name, or create a new serverless one."""
|
"""Return existing corpus by display name, or create a new one."""
|
||||||
for c in rag.list_corpora():
|
for c in rag.list_corpora():
|
||||||
if c.display_name == CORPUS_DISPLAY_NAME:
|
if c.display_name == CORPUS_DISPLAY_NAME:
|
||||||
print(f"Corpus '{CORPUS_DISPLAY_NAME}' already exists: {c.name}")
|
print(f"Corpus '{CORPUS_DISPLAY_NAME}' already exists: {c.name}")
|
||||||
return c
|
return c
|
||||||
|
|
||||||
print(f"Creating corpus '{CORPUS_DISPLAY_NAME}' in {LOCATION} (serverless)...")
|
print(f"Creating corpus '{CORPUS_DISPLAY_NAME}' in {LOCATION}...")
|
||||||
corpus = rag.create_corpus(
|
# NOTE: backend_config is intentionally omitted.
|
||||||
display_name=CORPUS_DISPLAY_NAME,
|
# SDK 1.153.1 has a bug where passing any backend_config crashes.
|
||||||
# RagManagedDb() is a no-arg marker class in SDK 1.153.1
|
# Serverless mode is already guaranteed by ensure_serverless_engine_config().
|
||||||
# Selecting it routes to serverless managed DB (basic tier)
|
corpus = rag.create_corpus(display_name=CORPUS_DISPLAY_NAME)
|
||||||
backend_config=rag.RagVectorDbConfig(
|
|
||||||
vector_db=rag.RagManagedDb()
|
|
||||||
),
|
|
||||||
)
|
|
||||||
print(f"✓ Corpus created: {corpus.name}")
|
print(f"✓ Corpus created: {corpus.name}")
|
||||||
return corpus
|
return corpus
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user