-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(samples): RAG Engine - Add Create Corpus for different Vector DB #12771
Open
holtskinner
wants to merge
7
commits into
main
Choose a base branch
from
rag-vector-db
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+320
−2
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0533bc
docs(samples): Add Create Corpus with Feature Store
holtskinner bbb7430
create corpus for weaviate
holtskinner 46dbd66
Add Weaviate Example for Retrieval Query
holtskinner edc0807
Add Pinecone Vector DB Sample
holtskinner e672850
typo
holtskinner e11867d
Add test for feature store
holtskinner 3e47962
Add Vector Search Sample
holtskinner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
|
||
from typing import Optional | ||
|
||
from vertexai.preview.rag import RagCorpus | ||
|
||
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||
|
||
|
||
def create_corpus_feature_store( | ||
feature_view_name: str, | ||
display_name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
) -> RagCorpus: | ||
# [START generativeaionvertexai_rag_create_corpus_feature_store] | ||
|
||
from vertexai.preview import rag | ||
import vertexai | ||
|
||
# TODO(developer): Update and un-comment below lines | ||
# PROJECT_ID = "your-project-id" | ||
# feature_view_name = "projects/{PROJECT_ID}/locations/{LOCATION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}/featureViews/{FEATURE_VIEW_ID}" | ||
# display_name = "test_corpus" | ||
# description = "Corpus Description" | ||
|
||
# Initialize Vertex AI API once per session | ||
vertexai.init(project=PROJECT_ID, location="us-central1") | ||
|
||
# Configure embedding model (Optional) | ||
embedding_model_config = rag.EmbeddingModelConfig( | ||
publisher_model="publishers/google/models/text-embedding-004" | ||
) | ||
|
||
# Configure Vector DB | ||
vector_db = rag.VertexFeatureStore(resource_name=feature_view_name) | ||
|
||
corpus = rag.create_corpus( | ||
display_name=display_name, | ||
description=description, | ||
embedding_model_config=embedding_model_config, | ||
vector_db=vector_db, | ||
) | ||
print(corpus) | ||
# Example response: | ||
# RagCorpus(name='projects/1234567890/locations/us-central1/ragCorpora/1234567890', | ||
# display_name='test_corpus', description='Corpus Description', embedding_model_config=... | ||
# ... | ||
|
||
# [END generativeaionvertexai_rag_create_corpus_feature_store] | ||
return corpus | ||
|
||
|
||
if __name__ == "__main__": | ||
create_corpus_feature_store( | ||
feature_view_name="projects/{PROJECT_ID}/locations/{LOCATION}/featureOnlineStores/{FEATURE_ONLINE_STORE_ID}/featureViews/{FEATURE_VIEW_ID}", | ||
display_name="test_corpus", | ||
description="Corpus Description", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
|
||
from typing import Optional | ||
|
||
from vertexai.preview.rag import RagCorpus | ||
|
||
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||
|
||
|
||
def create_corpus_pinecone( | ||
pinecone_index_name: str, | ||
pinecone_api_key_secret_manager_version: str, | ||
display_name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
) -> RagCorpus: | ||
# [START generativeaionvertexai_rag_create_corpus_pinecone] | ||
|
||
from vertexai.preview import rag | ||
import vertexai | ||
|
||
# TODO(developer): Update and un-comment below lines | ||
# PROJECT_ID = "your-project-id" | ||
# pinecone_index_name = "pinecone-index-name" | ||
# pinecone_api_key_secret_manager_version = "projects/{PROJECT_ID}/secrets/{SECRET_NAME}/versions/latest" | ||
# display_name = "test_corpus" | ||
# description = "Corpus Description" | ||
|
||
# Initialize Vertex AI API once per session | ||
vertexai.init(project=PROJECT_ID, location="us-central1") | ||
|
||
# Configure embedding model (Optional) | ||
embedding_model_config = rag.EmbeddingModelConfig( | ||
publisher_model="publishers/google/models/text-embedding-004" | ||
) | ||
|
||
# Configure Vector DB | ||
vector_db = rag.Pinecone( | ||
index_name=pinecone_index_name, | ||
api_key=pinecone_api_key_secret_manager_version, | ||
) | ||
|
||
corpus = rag.create_corpus( | ||
display_name=display_name, | ||
description=description, | ||
embedding_model_config=embedding_model_config, | ||
vector_db=vector_db, | ||
) | ||
print(corpus) | ||
# Example response: | ||
# RagCorpus(name='projects/1234567890/locations/us-central1/ragCorpora/1234567890', | ||
# display_name='test_corpus', description='Corpus Description', embedding_model_config=... | ||
# ... | ||
|
||
# [END generativeaionvertexai_rag_create_corpus_pinecone] | ||
return corpus | ||
|
||
|
||
if __name__ == "__main__": | ||
create_corpus_pinecone( | ||
pinecone_index_name="pinecone-index-name", | ||
pinecone_api_key_secret_manager_version="projects/{PROJECT_ID}/secrets/{SECRET_NAME}/versions/latest", | ||
display_name="test_corpus", | ||
description="Corpus Description", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
|
||
from typing import Optional | ||
|
||
from vertexai.preview.rag import RagCorpus | ||
|
||
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||
|
||
|
||
def create_corpus_vector_search( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No test cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please ensure that each snippet has at least 1 test case. |
||
vector_search_index_name: str, | ||
vector_search_index_endpoint_name: str, | ||
display_name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
) -> RagCorpus: | ||
# [START generativeaionvertexai_rag_create_corpus_vector_search] | ||
|
||
from vertexai.preview import rag | ||
import vertexai | ||
|
||
# TODO(developer): Update and un-comment below lines | ||
# PROJECT_ID = "your-project-id" | ||
# vector_search_index_name = "projects/{PROJECT_ID}/locations/{LOCATION}/indexes/{INDEX_ID}" | ||
# vector_search_index_endpoint_name = "projects/{PROJECT_ID}/locations/{LOCATION}/indexEndpoints/{INDEX_ENDPOINT_ID}" | ||
# display_name = "test_corpus" | ||
# description = "Corpus Description" | ||
|
||
# Initialize Vertex AI API once per session | ||
vertexai.init(project=PROJECT_ID, location="us-central1") | ||
|
||
# Configure embedding model (Optional) | ||
embedding_model_config = rag.EmbeddingModelConfig( | ||
publisher_model="publishers/google/models/text-embedding-004" | ||
) | ||
|
||
# Configure Vector DB | ||
vector_db = rag.VertexVectorSearch( | ||
index=vector_search_index_name, index_endpoint=vector_search_index_endpoint_name | ||
) | ||
|
||
corpus = rag.create_corpus( | ||
display_name=display_name, | ||
description=description, | ||
embedding_model_config=embedding_model_config, | ||
vector_db=vector_db, | ||
) | ||
print(corpus) | ||
# Example response: | ||
# RagCorpus(name='projects/1234567890/locations/us-central1/ragCorpora/1234567890', | ||
# display_name='test_corpus', description='Corpus Description', embedding_model_config=... | ||
# ... | ||
|
||
# [END generativeaionvertexai_rag_create_corpus_vector_search] | ||
return corpus | ||
|
||
|
||
if __name__ == "__main__": | ||
create_corpus_vector_search( | ||
vector_search_index_name="projects/{PROJECT_ID}/locations/{LOCATION}/indexes/{INDEX_ID}", | ||
vector_search_index_endpoint_name="projects/{PROJECT_ID}/locations/{LOCATION}/indexEndpoints/{INDEX_ENDPOINT_ID}", | ||
display_name="test_corpus", | ||
description="Corpus Description", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
|
||
from typing import Optional | ||
|
||
from vertexai.preview.rag import RagCorpus | ||
|
||
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||
|
||
|
||
def create_corpus_weaviate( | ||
weaviate_http_endpoint: str, | ||
weaviate_collection_name: str, | ||
weaviate_api_key_secret_manager_version: str, | ||
display_name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
) -> RagCorpus: | ||
# [START generativeaionvertexai_rag_create_corpus_weaviate] | ||
|
||
from vertexai.preview import rag | ||
import vertexai | ||
|
||
# TODO(developer): Update and un-comment below lines | ||
# PROJECT_ID = "your-project-id" | ||
# weaviate_http_endpoint = "weaviate-http-endpoint" | ||
# weaviate_collection_name = "weaviate-collection-name" | ||
# weaviate_api_key_secret_manager_version = "projects/{PROJECT_ID}/secrets/{SECRET_NAME}/versions/latest" | ||
# display_name = "test_corpus" | ||
# description = "Corpus Description" | ||
|
||
# Initialize Vertex AI API once per session | ||
vertexai.init(project=PROJECT_ID, location="us-central1") | ||
|
||
# Configure embedding model (Optional) | ||
embedding_model_config = rag.EmbeddingModelConfig( | ||
publisher_model="publishers/google/models/text-embedding-004" | ||
) | ||
|
||
# Configure Vector DB | ||
vector_db = rag.Weaviate( | ||
weaviate_http_endpoint=weaviate_http_endpoint, | ||
collection_name=weaviate_collection_name, | ||
api_key=weaviate_api_key_secret_manager_version, | ||
) | ||
|
||
corpus = rag.create_corpus( | ||
display_name=display_name, | ||
description=description, | ||
embedding_model_config=embedding_model_config, | ||
vector_db=vector_db, | ||
) | ||
print(corpus) | ||
# Example response: | ||
# RagCorpus(name='projects/1234567890/locations/us-central1/ragCorpora/1234567890', | ||
# display_name='test_corpus', description='Corpus Description', embedding_model_config=... | ||
# ... | ||
|
||
# [END generativeaionvertexai_rag_create_corpus_weaviate] | ||
return corpus | ||
|
||
|
||
if __name__ == "__main__": | ||
create_corpus_weaviate( | ||
weaviate_http_endpoint="weaviate-http-endpoint", | ||
weaviate_collection_name="weaviate-collection-name", | ||
weaviate_api_key_secret_manager_version="projects/{PROJECT_ID}/secrets/{SECRET_NAME}/versions/latest", | ||
display_name="test_corpus", | ||
description="Corpus Description", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see test cases for
create_corpus_pinecone