Skip to content

Commit afa5610

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: RAG - add timeout options for create_corpus, update_corpus and update_rag_engine_config for both v1 and v1beta1 apis.
PiperOrigin-RevId: 783950625
1 parent 1315df7 commit afa5610

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

vertexai/preview/rag/rag_data.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,18 @@ def create_corpus(
7373
corpus_type_config: Optional[RagCorpusTypeConfig] = None,
7474
embedding_model_config: Optional[EmbeddingModelConfig] = None,
7575
vector_db: Optional[
76-
Union[Weaviate, VertexFeatureStore, VertexVectorSearch, Pinecone, RagManagedDb]
76+
Union[
77+
Weaviate,
78+
VertexFeatureStore,
79+
VertexVectorSearch,
80+
Pinecone,
81+
RagManagedDb,
82+
]
7783
] = None,
7884
vertex_ai_search_config: Optional[VertexAiSearchConfig] = None,
7985
backend_config: Optional[RagVectorDbConfig] = None,
8086
encryption_spec: Optional[EncryptionSpec] = None,
87+
timeout: int = 600,
8188
) -> RagCorpus:
8289
"""Creates a new RagCorpus resource.
8390
@@ -95,21 +102,22 @@ def create_corpus(
95102
96103
Args:
97104
display_name: If not provided, SDK will create one. The display name of
98-
the RagCorpus. The name can be up to 128 characters long and can consist
99-
of any UTF-8 characters.
105+
the RagCorpus. The name can be up to 128 characters long and can consist
106+
of any UTF-8 characters.
100107
description: The description of the RagCorpus.
101108
corpus_type_config: The corpus type config of the RagCorpus.
102109
embedding_model_config: The embedding model config.
103110
Note: Deprecated. Use backend_config instead.
104111
vector_db: The vector db config of the RagCorpus. If unspecified, the
105-
default database Spanner is used.
112+
default database Spanner is used.
106113
Note: Deprecated. Use backend_config instead.
107114
vertex_ai_search_config: The Vertex AI Search config of the RagCorpus.
108115
Note: embedding_model_config or vector_db cannot be set if
109-
vertex_ai_search_config is specified.
116+
vertex_ai_search_config is specified.
110117
backend_config: The backend config of the RagCorpus. It can specify a
111-
Vector DB and/or the embedding model config.
118+
Vector DB and/or the embedding model config.
112119
encryption_spec: The encryption spec of the RagCorpus.
120+
timeout: Default is 600 seconds.
113121
114122
Returns:
115123
RagCorpus.
@@ -186,7 +194,7 @@ def create_corpus(
186194
response = client.create_rag_corpus(request=request)
187195
except Exception as e:
188196
raise RuntimeError("Failed in RagCorpus creation due to: ", e) from e
189-
return _gapic_utils.convert_gapic_to_rag_corpus(response.result(timeout=600))
197+
return _gapic_utils.convert_gapic_to_rag_corpus(response.result(timeout=timeout))
190198

191199

192200
def update_corpus(
@@ -204,6 +212,7 @@ def update_corpus(
204212
] = None,
205213
vertex_ai_search_config: Optional[VertexAiSearchConfig] = None,
206214
backend_config: Optional[RagVectorDbConfig] = None,
215+
timeout: int = 600,
207216
) -> RagCorpus:
208217
"""Updates a RagCorpus resource.
209218
@@ -231,12 +240,13 @@ def update_corpus(
231240
description will not be updated.
232241
vector_db: The vector db config of the RagCorpus. If not provided, the
233242
vector db will not be updated.
234-
vertex_ai_search_config: The Vertex AI Search config of the RagCorpus.
235-
If not provided, the Vertex AI Search config will not be updated.
243+
vertex_ai_search_config: The Vertex AI Search config of the RagCorpus. If
244+
not provided, the Vertex AI Search config will not be updated.
236245
Note: embedding_model_config or vector_db cannot be set if
237-
vertex_ai_search_config is specified.
238-
backend_config: The backend config of the RagCorpus. Specifies a Vector
239-
DB and/or the embedding model config.
246+
vertex_ai_search_config is specified.
247+
backend_config: The backend config of the RagCorpus. Specifies a Vector DB
248+
and/or the embedding model config.
249+
timeout: Default is 600 seconds.
240250
241251
Returns:
242252
RagCorpus.
@@ -286,7 +296,7 @@ def update_corpus(
286296
except Exception as e:
287297
raise RuntimeError("Failed in RagCorpus update due to: ", e) from e
288298
return _gapic_utils.convert_gapic_to_rag_corpus_no_embedding_model_config(
289-
response.result(timeout=600)
299+
response.result(timeout=timeout)
290300
)
291301

292302

@@ -998,6 +1008,7 @@ def delete_file(name: str, corpus_name: Optional[str] = None) -> None:
9981008

9991009
def update_rag_engine_config(
10001010
rag_engine_config: RagEngineConfig,
1011+
timeout: int = 600,
10011012
) -> RagEngineConfig:
10021013
"""Update RagEngineConfig.
10031014
@@ -1019,6 +1030,7 @@ def update_rag_engine_config(
10191030
10201031
Args:
10211032
rag_engine_config: The RagEngineConfig to update.
1033+
timeout: Default is 600 seconds.
10221034
10231035
Raises:
10241036
RuntimeError: Failed in RagEngineConfig update due to exception.
@@ -1034,7 +1046,9 @@ def update_rag_engine_config(
10341046
response = client.update_rag_engine_config(request=request)
10351047
except Exception as e:
10361048
raise RuntimeError("Failed in RagEngineConfig update due to: ", e) from e
1037-
return _gapic_utils.convert_gapic_to_rag_engine_config(response.result(timeout=600))
1049+
return _gapic_utils.convert_gapic_to_rag_engine_config(
1050+
response.result(timeout=timeout)
1051+
)
10381052

10391053

10401054
def get_rag_engine_config(name: str) -> RagEngineConfig:

vertexai/rag/rag_data.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def create_corpus(
7676
]
7777
] = None,
7878
encryption_spec: Optional[EncryptionSpec] = None,
79+
timeout: int = 600,
7980
) -> RagCorpus:
8081
"""Creates a new RagCorpus resource.
8182
@@ -93,15 +94,17 @@ def create_corpus(
9394
9495
Args:
9596
display_name: If not provided, SDK will create one. The display name of
96-
the RagCorpus. The name can be up to 128 characters long and can
97-
consist of any UTF-8 characters.
97+
the RagCorpus. The name can be up to 128 characters long and can consist
98+
of any UTF-8 characters.
9899
description: The description of the RagCorpus.
99100
vertex_ai_search_config: The Vertex AI Search config of the RagCorpus.
100101
Note: backend_config cannot be set if vertex_ai_search_config is
101-
specified.
102-
backend_config: The backend config of the RagCorpus, specifying a
103-
data store and/or embedding model.
102+
specified.
103+
backend_config: The backend config of the RagCorpus, specifying a data
104+
store and/or embedding model.
104105
encryption_spec: The encryption spec of the RagCorpus.
106+
timeout: Default is 600 seconds.
107+
105108
Returns:
106109
RagCorpus.
107110
Raises:
@@ -146,7 +149,7 @@ def create_corpus(
146149
response = client.create_rag_corpus(request=request)
147150
except Exception as e:
148151
raise RuntimeError("Failed in RagCorpus creation due to: ", e) from e
149-
return _gapic_utils.convert_gapic_to_rag_corpus(response.result(timeout=600))
152+
return _gapic_utils.convert_gapic_to_rag_corpus(response.result(timeout=timeout))
150153

151154

152155
def update_corpus(
@@ -160,10 +163,12 @@ def update_corpus(
160163
None,
161164
]
162165
] = None,
166+
timeout: int = 600,
163167
) -> RagCorpus:
164-
"""Updates a RagCorpus resource. It is intended to update 3rd party vector
165-
DBs (Vector Search, Vertex AI Feature Store, Weaviate, Pinecone) but not
166-
Vertex RagManagedDb.
168+
"""Updates a RagCorpus resource.
169+
170+
It is intended to update 3rd party vector DBs (Vector Search, Vertex AI
171+
Feature Store, Weaviate, Pinecone) but not Vertex RagManagedDb.
167172
168173
Example usage:
169174
```
@@ -187,12 +192,13 @@ def update_corpus(
187192
and can consist of any UTF-8 characters.
188193
description: The description of the RagCorpus. If not provided, the
189194
description will not be updated.
190-
vertex_ai_search_config: The Vertex AI Search config of the RagCorpus.
191-
If not provided, the Vertex AI Search config will not be updated.
195+
vertex_ai_search_config: The Vertex AI Search config of the RagCorpus. If
196+
not provided, the Vertex AI Search config will not be updated.
192197
Note: backend_config cannot be set if vertex_ai_search_config is
193-
specified.
194-
backend_config: The backend config of the RagCorpus, specifying a
195-
data store and/or embedding model.
198+
specified.
199+
backend_config: The backend config of the RagCorpus, specifying a data
200+
store and/or embedding model.
201+
timeout: Default is 600 seconds.
196202
197203
Returns:
198204
RagCorpus.
@@ -239,7 +245,7 @@ def update_corpus(
239245
except Exception as e:
240246
raise RuntimeError("Failed in RagCorpus update due to: ", e) from e
241247
return _gapic_utils.convert_gapic_to_rag_corpus_no_embedding_model_config(
242-
response.result(timeout=600)
248+
response.result(timeout=timeout)
243249
)
244250

245251

@@ -902,6 +908,7 @@ def delete_file(name: str, corpus_name: Optional[str] = None) -> None:
902908

903909
def update_rag_engine_config(
904910
rag_engine_config: RagEngineConfig,
911+
timeout: int = 600,
905912
) -> RagEngineConfig:
906913
"""Update RagEngineConfig.
907914
@@ -923,6 +930,7 @@ def update_rag_engine_config(
923930
924931
Args:
925932
rag_engine_config: The RagEngineConfig to update.
933+
timeout: Default is 600 seconds.
926934
927935
Raises:
928936
RuntimeError: Failed in RagEngineConfig update due to exception.
@@ -938,7 +946,9 @@ def update_rag_engine_config(
938946
response = client.update_rag_engine_config(request=request)
939947
except Exception as e:
940948
raise RuntimeError("Failed in RagEngineConfig update due to: ", e) from e
941-
return _gapic_utils.convert_gapic_to_rag_engine_config(response.result(timeout=600))
949+
return _gapic_utils.convert_gapic_to_rag_engine_config(
950+
response.result(timeout=timeout)
951+
)
942952

943953

944954
def get_rag_engine_config(name: str) -> RagEngineConfig:

0 commit comments

Comments
 (0)