Skip to content

Commit a1f8bc2

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
docs: updated example usage in docstring for rag_retrieval preview and GA
docs: updated example usage in docstring for rag_store preview and GA PiperOrigin-RevId: 700577610
1 parent 4288fec commit a1f8bc2

File tree

4 files changed

+81
-35
lines changed

4 files changed

+81
-35
lines changed

vertexai/preview/rag/rag_retrieval.py

+30-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def retrieval_query(
4343
4444
vertexai.init(project="my-project")
4545
46+
# Using deprecated parameters
4647
results = vertexai.preview.rag.retrieval_query(
4748
text="Why is the sky blue?",
4849
rag_resources=[vertexai.preview.rag.RagResource(
@@ -53,6 +54,26 @@ def retrieval_query(
5354
vector_distance_threshold=0.5,
5455
vector_search_alpha=0.5,
5556
)
57+
58+
# Using RagRetrievalConfig. Equivalent to the above example.
59+
config = vertexai.preview.rag.rag_retrieval_config(
60+
top_k=2,
61+
filter=vertexai.preview.rag.rag_retrieval_config.filter(
62+
vector_distance_threshold=0.5
63+
),
64+
hybrid_search=vertexai.preview.rag.rag_retrieval_config.hybrid_search(
65+
alpha=0.5
66+
),
67+
)
68+
69+
results = vertexai.preview.rag.retrieval_query(
70+
text="Why is the sky blue?",
71+
rag_resources=[vertexai.preview.rag.RagResource(
72+
rag_corpus="projects/my-project/locations/us-central1/ragCorpora/rag-corpus-1",
73+
rag_file_ids=["rag-file-1", "rag-file-2", ...],
74+
)],
75+
rag_retrieval_config=config,
76+
)
5677
```
5778
5879
Args:
@@ -61,17 +82,20 @@ def retrieval_query(
6182
only or ragfiles. Currently only support one corpus or multiple files
6283
from one corpus. In the future we may open up multiple corpora support.
6384
rag_corpora: If rag_resources is not specified, use rag_corpora as a list
64-
of rag corpora names.
65-
similarity_top_k: The number of contexts to retrieve.
85+
of rag corpora names. Deprecated. Use rag_resources instead.
86+
similarity_top_k: The number of contexts to retrieve. Deprecated. Use
87+
rag_retrieval_config.top_k instead.
6688
vector_distance_threshold: Optional. Only return contexts with vector
67-
distance smaller than the threshold.
89+
distance smaller than the threshold. Deprecated. Use
90+
rag_retrieval_config.filter.vector_distance_threshold instead.
6891
vector_search_alpha: Optional. Controls the weight between dense and
6992
sparse vector search results. The range is [0, 1], where 0 means
7093
sparse vector search only and 1 means dense vector search only.
71-
The default value is 0.5.
94+
The default value is 0.5. Deprecated. Use
95+
rag_retrieval_config.hybrid_search.alpha instead.
7296
rag_retrieval_config: Optional. The config containing the retrieval
73-
parameters, including similarity_top_k, vector_distance_threshold,
74-
vector_search_alpha, and hybrid_search.
97+
parameters, including top_k, vector_distance_threshold,
98+
and alpha.
7599
76100
Returns:
77101
RetrieveContextsResonse.

vertexai/preview/rag/rag_store.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,32 @@ def __init__(
6161
6262
vertexai.init(project="my-project")
6363
64-
results = vertexai.preview.rag.retrieval_query(
65-
text="Why is the sky blue?",
66-
rag_resources=[vertexai.preview.rag.RagResource(
67-
rag_corpus="projects/my-project/locations/us-central1/ragCorpora/rag-corpus-1",
68-
rag_file_ids=["rag-file-1", "rag-file-2", ...],
69-
)],
70-
similarity_top_k=2,
71-
vector_distance_threshold=0.5,
64+
# Using deprecated parameters
65+
tool = Tool.from_retrieval(
66+
retrieval=vertexai.preview.rag.Retrieval(
67+
source=vertexai.preview.rag.VertexRagStore(
68+
rag_corpora=["projects/my-project/locations/us-central1/ragCorpora/rag-corpus-1"],
69+
similarity_top_k=3,
70+
vector_distance_threshold=0.4,
71+
),
72+
)
73+
)
74+
75+
# Using RagRetrievalConfig. Equivalent to the above example.
76+
config = vertexai.preview.rag.RagRetrievalConfig(
77+
top_k=2,
78+
filter=vertexai.preview.rag.RagRetrievalConfig.Filter(
79+
vector_distance_threshold=0.5
80+
),
81+
)
82+
83+
tool = Tool.from_retrieval(
84+
retrieval=vertexai.preview.rag.Retrieval(
85+
source=vertexai.preview.rag.VertexRagStore(
86+
rag_corpora=["projects/my-project/locations/us-central1/ragCorpora/rag-corpus-1"],
87+
rag_retrieval_config=config,
88+
),
89+
)
7290
)
7391
```
7492
@@ -78,16 +96,15 @@ def __init__(
7896
corpus or multiple files from one corpus. In the future we
7997
may open up multiple corpora support.
8098
rag_corpora: If rag_resources is not specified, use rag_corpora as a
81-
list of rag corpora names.
99+
list of rag corpora names. Deprecated. Use rag_resources instead.
82100
similarity_top_k: Number of top k results to return from the selected
83-
corpora.
101+
corpora. Deprecated. Use rag_retrieval_config.top_k instead.
84102
vector_distance_threshold (float):
85103
Optional. Only return results with vector distance smaller
86-
than the threshold.
104+
than the threshold. Deprecated. Use
105+
rag_retrieval_config.filter.vector_distance_threshold instead.
87106
rag_retrieval_config: Optional. The config containing the retrieval
88-
parameters, including similarity_top_k, hybrid search alpha,
89-
and vector_distance_threshold.
90-
107+
parameters, including top_k and vector_distance_threshold.
91108
"""
92109

93110
if rag_resources:

vertexai/rag/rag_retrieval.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ def retrieval_query(
3838
3939
vertexai.init(project="my-project")
4040
41-
results = vertexai.preview.rag.retrieval_query(
41+
config = vertexai.rag.rag_retrieval_config(
42+
top_k=2,
43+
filter=vertexai.rag.rag_retrieval_config.filter(
44+
vector_distance_threshold=0.5
45+
),
46+
)
47+
48+
results = vertexai.rag.retrieval_query(
4249
text="Why is the sky blue?",
43-
rag_resources=[vertexai.preview.rag.RagResource(
50+
rag_resources=[vertexai.rag.RagResource(
4451
rag_corpus="projects/my-project/locations/us-central1/ragCorpora/rag-corpus-1",
4552
rag_file_ids=["rag-file-1", "rag-file-2", ...],
4653
)],
47-
similarity_top_k=2,
48-
vector_distance_threshold=0.5,
54+
rag_retrieval_config=config,
4955
)
5056
```
5157
@@ -55,8 +61,7 @@ def retrieval_query(
5561
only or ragfiles. Currently only support one corpus or multiple files
5662
from one corpus. In the future we may open up multiple corpora support.
5763
rag_retrieval_config: Optional. The config containing the retrieval
58-
parameters, including similarity_top_k, vector_distance_threshold,
59-
and hybrid_search.
64+
parameters, including similarity_top_k and vector_distance_threshold
6065
6166
Returns:
6267
RetrieveContextsResonse.

vertexai/rag/rag_store.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ def __init__(
5757
5858
vertexai.init(project="my-project")
5959
60-
config = vertexai.preview.rag.RagRetrievalConfig(
60+
config = vertexai.rag.RagRetrievalConfig(
6161
top_k=2,
62-
filter=vertexai.preview.rag.RagRetrievalConfig.Filter(
62+
filter=vertexai.rag.RagRetrievalConfig.Filter(
6363
vector_distance_threshold=0.5
6464
),
6565
)
6666
67-
results = vertexai.preview.rag.retrieval_query(
68-
text="Why is the sky blue?",
69-
rag_resources=[vertexai.preview.rag.RagResource(
70-
rag_corpus="projects/my-project/locations/us-central1/ragCorpora/rag-corpus-1",
71-
rag_file_ids=["rag-file-1", "rag-file-2", ...],
72-
)],
73-
rag_retrieval_config=config,
67+
tool = Tool.from_retrieval(
68+
retrieval=vertexai.rag.Retrieval(
69+
source=vertexai.rag.VertexRagStore(
70+
rag_corpora=["projects/my-project/locations/us-central1/ragCorpora/rag-corpus-1"],
71+
rag_retrieval_config=config,
72+
),
73+
)
7474
)
7575
```
7676

0 commit comments

Comments
 (0)