Skip to content

Commit fad4dbf

Browse files
sararobcopybara-github
authored andcommitted
docs: GenAI client - Add example usage to RAG docstrings
PiperOrigin-RevId: 948979257
1 parent 62bc783 commit fad4dbf

1 file changed

Lines changed: 146 additions & 11 deletions

File tree

agentplatform/_genai/rag.py

Lines changed: 146 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,6 +2926,17 @@ def create_corpus(
29262926
29272927
Returns:
29282928
The created RagCorpus.
2929+
2930+
Example usage:
2931+
2932+
```
2933+
corpus = client.rag.create_corpus(
2934+
rag_corpus=types.RagCorpus(
2935+
display_name="test-corpus",
2936+
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
2937+
),
2938+
)
2939+
```
29292940
"""
29302941
operation = self._create_corpus(rag_corpus=rag_corpus, config=config)
29312942

@@ -2954,6 +2965,14 @@ def delete_corpus(
29542965
name: The name of the RagCorpus to delete, formatted as
29552966
`projects/{project}/locations/{location}/ragCorpora/{corpus_id}`.
29562967
config: The configuration to use for the RagCorpus delete request.
2968+
2969+
Example usage:
2970+
2971+
```
2972+
client.rag.delete_corpus(
2973+
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
2974+
)
2975+
```
29572976
"""
29582977

29592978
operation = self._delete_corpus(name=name, config=config)
@@ -2983,6 +3002,14 @@ def delete_file(
29833002
name: The name of the RagFile to delete, formatted as
29843003
`projects/{project}/locations/{location}/ragCorpora/{corpus_id}/ragFiles/{file_id}`.
29853004
config: The configuration to use for the RagFile delete request.
3005+
3006+
Example usage:
3007+
3008+
```
3009+
client.rag.delete_file(
3010+
name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragFiles/987654321",
3011+
)
3012+
```
29863013
"""
29873014
operation = self._delete_file(name=name, config=config)
29883015

@@ -3016,7 +3043,19 @@ def update_corpus(
30163043
30173044
Returns:
30183045
The updated RagCorpus.
3046+
3047+
Example usage:
3048+
3049+
```
3050+
client.rag.update_corpus(
3051+
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
3052+
rag_corpus=types.RagCorpus(
3053+
display_name="Updated corpus name",
3054+
),
3055+
)
3056+
```
30193057
"""
3058+
30203059
operation = self._update_corpus(name=name, rag_corpus=rag_corpus, config=config)
30213060

30223061
operation = _operations_utils.await_operation(
@@ -3046,6 +3085,19 @@ def update_config(
30463085
30473086
Returns:
30483087
The updated RagEngineConfig.
3088+
3089+
Example usage:
3090+
3091+
```
3092+
client.rag.update_config(
3093+
updated_config=types.RagEngineConfig(
3094+
name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragEngineConfig/123456789",
3095+
rag_managed_db_config=types.RagManagedDbConfig(
3096+
basic=types.RagManagedDbConfigBasic()
3097+
),
3098+
),
3099+
)
3100+
```
30493101
"""
30503102
operation = self._update_config(
30513103
updated_config=updated_config, config=request_config
@@ -3073,25 +3125,25 @@ def import_files(
30733125
"""
30743126
Imports files into a Rag Corpus. To get a list of all files on the corpus after calling import_files, call list_files.
30753127
3128+
Args:
3129+
name: The name of the Rag Corpus to import files into, format:
3130+
`projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
3131+
import_config: The configuration for importing files, including source files and processing options.
3132+
config: The configuration to use for the import request.
3133+
3134+
Returns:
3135+
The ImportRagFilesResponse from the import files operation.
3136+
30763137
Example usage:
30773138
30783139
```
3079-
client.rag.import_files(
3140+
import_files_response = client.rag.import_files(
30803141
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
30813142
import_config=types.ImportRagFilesConfig(
30823143
gcs_source=types.GcsSource(uris=["gs://test-bucket/test-file.pdf"]),
30833144
),
30843145
)
30853146
```
3086-
3087-
Args:
3088-
name: The name of the Rag Corpus to import files into, format:
3089-
`projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
3090-
import_config: The configuration for importing files, including source files and processing options.
3091-
config: The configuration to use for the import request.
3092-
3093-
Returns:
3094-
The ImportRagFilesResponse from the import files operation.
30953147
"""
30963148
if isinstance(import_config, dict):
30973149
import_config = types.ImportRagFilesConfig.model_validate(import_config)
@@ -3148,6 +3200,22 @@ def upload_file(
31483200
31493201
Returns:
31503202
The uploaded RagFile.
3203+
3204+
Example usage:
3205+
3206+
```
3207+
rag_file = client.rag.upload_file(
3208+
corpus_name="projects/test-project/locations/us-central1/ragCorpora/123456789",
3209+
path="/path/to/file.pdf",
3210+
display_name="test-file",
3211+
upload_rag_file_config=types.UploadRagFileConfig(
3212+
chunk_config=types.ChunkConfig(
3213+
chunk_size=1024,
3214+
chunk_overlap=128,
3215+
),
3216+
),
3217+
)
3218+
```
31513219
"""
31523220

31533221
if not display_name:
@@ -4534,6 +4602,17 @@ async def create_corpus(
45344602
45354603
Returns:
45364604
The created RagCorpus.
4605+
4606+
Example usage:
4607+
4608+
```
4609+
corpus = await client.aio.rag.create_corpus(
4610+
rag_corpus=types.RagCorpus(
4611+
display_name="test-corpus",
4612+
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4613+
),
4614+
)
4615+
```
45374616
"""
45384617
operation = await self._create_corpus(rag_corpus=rag_corpus, config=config)
45394618

@@ -4562,6 +4641,14 @@ async def delete_corpus(
45624641
name: The name of the RagCorpus to delete, formatted as
45634642
`projects/{project}/locations/{location}/ragCorpora/{corpus_id}`.
45644643
config: The configuration to use for the RagCorpus delete request.
4644+
4645+
Example usage:
4646+
4647+
```
4648+
await client.aio.rag.delete_corpus(
4649+
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4650+
)
4651+
```
45654652
"""
45664653
operation = await self._delete_corpus(name=name, config=config)
45674654

@@ -4590,6 +4677,14 @@ async def delete_file(
45904677
name: The name of the RagFile to delete, formatted as
45914678
`projects/{project}/locations/{location}/ragCorpora/{corpus_id}/ragFiles/{file_id}`.
45924679
config: The configuration to use for the RagFile delete request.
4680+
4681+
Example usage:
4682+
4683+
```
4684+
await client.aio.rag.delete_file(
4685+
name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragFiles/987654321",
4686+
)
4687+
```
45934688
"""
45944689
operation = await self._delete_file(name=name, config=config)
45954690

@@ -4623,6 +4718,17 @@ async def update_corpus(
46234718
46244719
Returns:
46254720
The updated RagCorpus.
4721+
4722+
Example usage:
4723+
4724+
```
4725+
await client.aio.rag.update_corpus(
4726+
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4727+
rag_corpus=types.RagCorpus(
4728+
display_name="Updated corpus name",
4729+
),
4730+
)
4731+
```
46264732
"""
46274733
operation = await self._update_corpus(
46284734
name=name, rag_corpus=rag_corpus, config=config
@@ -4655,6 +4761,19 @@ async def update_config(
46554761
46564762
Returns:
46574763
The updated RagEngineConfig.
4764+
4765+
Example usage:
4766+
4767+
```
4768+
await client.aio.rag.update_config(
4769+
updated_config=types.RagEngineConfig(
4770+
name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragEngineConfig/123456789",
4771+
rag_managed_db_config=types.RagManagedDbConfig(
4772+
basic=types.RagManagedDbConfigBasic()
4773+
)
4774+
),
4775+
)
4776+
```
46584777
"""
46594778
operation = await self._update_config(
46604779
updated_config=updated_config, config=request_config
@@ -4685,7 +4804,7 @@ async def import_files(
46854804
Example usage:
46864805
46874806
```
4688-
client.rag.import_files(
4807+
import_files_response = await client.aio.rag.import_files(
46894808
name="projects/test-project/locations/us-central1/ragCorpora/123456789",
46904809
import_config=types.ImportRagFilesConfig(
46914810
gcs_source=types.GcsSource(uris=["gs://test-bucket/test-file.pdf"]),
@@ -4758,6 +4877,22 @@ async def upload_file(
47584877
47594878
Returns:
47604879
The uploaded RagFile.
4880+
4881+
Example usage:
4882+
4883+
```
4884+
rag_file = await client.aio.rag.upload_file(
4885+
corpus_name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4886+
path="/path/to/file.pdf",
4887+
display_name="test-file",
4888+
upload_rag_file_config=types.UploadRagFileConfig(
4889+
chunk_config=types.ChunkConfig(
4890+
chunk_size=1024,
4891+
chunk_overlap=128,
4892+
),
4893+
),
4894+
)
4895+
```
47614896
"""
47624897

47634898
if not display_name:

0 commit comments

Comments
 (0)