GeezerVison is showing github.com — feat: Adding Vertex Vector Search Vector DB option for RAG corpuses t… · googleapis/python-aiplatform@d4193f2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: tests/unit/vertex_rag/test_rag_constants.py +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 | JiraSource, | 30 | 30 | JiraQuery, | 31 | 31 | Weaviate, | | 32 | + VertexVectorSearch, | 32 | 33 | VertexFeatureStore, | 33 | 34 | ) | 34 | 35 | from google.cloud.aiplatform_v1beta1 import ( | | 78 | 79 | index_name=TEST_PINECONE_INDEX_NAME, | 79 | 80 | api_key=TEST_PINECONE_API_KEY_SECRET_VERSION, | 80 | 81 | ) | | 82 | +TEST_VERTEX_VECTOR_SEARCH_INDEX_ENDPOINT = "test-vector-search-index-endpoint" | | 83 | +TEST_VERTEX_VECTOR_SEARCH_INDEX = "test-vector-search-index" | | 84 | +TEST_VERTEX_VECTOR_SEARCH_CONFIG = VertexVectorSearch( | | 85 | + index_endpoint=TEST_VERTEX_VECTOR_SEARCH_INDEX_ENDPOINT, | | 86 | + index=TEST_VERTEX_VECTOR_SEARCH_INDEX, | | 87 | +) | 81 | 88 | TEST_VERTEX_FEATURE_STORE_RESOURCE_NAME = "test-feature-view-resource-name" | 82 | 89 | TEST_GAPIC_RAG_CORPUS = GapicRagCorpus( | 83 | 90 | name=TEST_RAG_CORPUS_RESOURCE_NAME, | | 115 | 122 | ), | 116 | 123 | ), | 117 | 124 | ) | | 125 | +TEST_GAPIC_RAG_CORPUS_VERTEX_VECTOR_SEARCH = GapicRagCorpus( | | 126 | + name=TEST_RAG_CORPUS_RESOURCE_NAME, | | 127 | + display_name=TEST_CORPUS_DISPLAY_NAME, | | 128 | + description=TEST_CORPUS_DISCRIPTION, | | 129 | + rag_vector_db_config=RagVectorDbConfig( | | 130 | + vertex_vector_search=RagVectorDbConfig.VertexVectorSearch( | | 131 | + index_endpoint=TEST_VERTEX_VECTOR_SEARCH_INDEX_ENDPOINT, | | 132 | + index=TEST_VERTEX_VECTOR_SEARCH_INDEX, | | 133 | + ), | | 134 | + ), | | 135 | +) | 118 | 136 | TEST_GAPIC_RAG_CORPUS_PINECONE = GapicRagCorpus( | 119 | 137 | name=TEST_RAG_CORPUS_RESOURCE_NAME, | 120 | 138 | display_name=TEST_CORPUS_DISPLAY_NAME, | | 158 | 176 | description=TEST_CORPUS_DISCRIPTION, | 159 | 177 | vector_db=TEST_PINECONE_CONFIG, | 160 | 178 | ) | | 179 | +TEST_RAG_CORPUS_VERTEX_VECTOR_SEARCH = RagCorpus( | | 180 | + name=TEST_RAG_CORPUS_RESOURCE_NAME, | | 181 | + display_name=TEST_CORPUS_DISPLAY_NAME, | | 182 | + description=TEST_CORPUS_DISCRIPTION, | | 183 | + vector_db=TEST_VERTEX_VECTOR_SEARCH_CONFIG, | | 184 | +) | 161 | 185 | TEST_PAGE_TOKEN = "test-page-token" | 162 | 186 |
| 163 | 187 | # RagFiles | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/vertex_rag/test_rag_data.py +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -79,6 +79,23 @@ def create_rag_corpus_mock_vertex_feature_store(): | 79 | 79 | yield create_rag_corpus_mock_vertex_feature_store | 80 | 80 |
| 81 | 81 |
| | 82 | +@pytest.fixture | | 83 | +def create_rag_corpus_mock_vertex_vector_search(): | | 84 | + with mock.patch.object( | | 85 | + VertexRagDataServiceClient, | | 86 | + "create_rag_corpus", | | 87 | + ) as create_rag_corpus_mock_vertex_vector_search: | | 88 | + create_rag_corpus_lro_mock = mock.Mock(ga_operation.Operation) | | 89 | + create_rag_corpus_lro_mock.done.return_value = True | | 90 | + create_rag_corpus_lro_mock.result.return_value = ( | | 91 | + tc.TEST_GAPIC_RAG_CORPUS_VERTEX_VECTOR_SEARCH | | 92 | + ) | | 93 | + create_rag_corpus_mock_vertex_vector_search.return_value = ( | | 94 | + create_rag_corpus_lro_mock | | 95 | + ) | | 96 | + yield create_rag_corpus_mock_vertex_vector_search | | 97 | + | | 98 | + | 82 | 99 | @pytest.fixture | 83 | 100 | def create_rag_corpus_mock_pinecone(): | 84 | 101 | with mock.patch.object( | @@ -257,6 +274,15 @@ def test_create_corpus_vertex_feature_store_success(self): | 257 | 274 |
| 258 | 275 | rag_corpus_eq(rag_corpus, tc.TEST_RAG_CORPUS_VERTEX_FEATURE_STORE) | 259 | 276 |
| | 277 | + @pytest.mark.usefixtures("create_rag_corpus_mock_vertex_vector_search") | | 278 | + def test_create_corpus_vertex_vector_search_success(self): | | 279 | + rag_corpus = rag.create_corpus( | | 280 | + display_name=tc.TEST_CORPUS_DISPLAY_NAME, | | 281 | + vector_db=tc.TEST_VERTEX_VECTOR_SEARCH_CONFIG, | | 282 | + ) | | 283 | + | | 284 | + rag_corpus_eq(rag_corpus, tc.TEST_RAG_CORPUS_VERTEX_VECTOR_SEARCH) | | 285 | + | 260 | 286 | @pytest.mark.usefixtures("create_rag_corpus_mock_pinecone") | 261 | 287 | def test_create_corpus_pinecone_success(self): | 262 | 288 | rag_corpus = rag.create_corpus( | |
Collapse file Copy file name to clipboardExpand all lines: vertexai/preview/rag/__init__.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 47 | 47 | SlackChannel, | 48 | 48 | SlackChannelsSource, | 49 | 49 | VertexFeatureStore, | | 50 | + VertexVectorSearch, | 50 | 51 | Weaviate, | 51 | 52 | ) | 52 | 53 |
| | 64 | 65 | "SlackChannelsSource", | 65 | 66 | "VertexFeatureStore", | 66 | 67 | "VertexRagStore", | | 68 | + "VertexVectorSearch", | 67 | 69 | "Weaviate", | 68 | 70 | "create_corpus", | 69 | 71 | "delete_corpus", | |
Collapse file Copy file name to clipboardExpand all lines: vertexai/preview/rag/rag_data.py +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 50 | 50 | RagFile, | 51 | 51 | SlackChannelsSource, | 52 | 52 | VertexFeatureStore, | | 53 | + VertexVectorSearch, | 53 | 54 | Weaviate, | 54 | 55 | ) | 55 | 56 |
| @@ -58,7 +59,9 @@ def create_corpus( | 58 | 59 | display_name: Optional[str] = None, | 59 | 60 | description: Optional[str] = None, | 60 | 61 | embedding_model_config: Optional[EmbeddingModelConfig] = None, | 61 | | - vector_db: Optional[Union[Weaviate, VertexFeatureStore, Pinecone]] = None, | | 62 | + vector_db: Optional[ | | 63 | + Union[Weaviate, VertexFeatureStore, VertexVectorSearch, Pinecone] | | 64 | + ] = None, | 62 | 65 | ) -> RagCorpus: | 63 | 66 | """Creates a new RagCorpus resource. | 64 | 67 |
| |
Collapse file Copy file name to clipboardExpand all lines: vertexai/preview/rag/utils/_gapic_utils.py +20-4Lines changed: 20 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 44 | 44 | SlackChannelsSource, | 45 | 45 | JiraSource, | 46 | 46 | VertexFeatureStore, | | 47 | + VertexVectorSearch, | 47 | 48 | Weaviate, | 48 | 49 | ) | 49 | 50 |
| @@ -99,8 +100,8 @@ def convert_gapic_to_embedding_model_config( | 99 | 100 |
| 100 | 101 | def convert_gapic_to_vector_db( | 101 | 102 | gapic_vector_db: RagVectorDbConfig, | 102 | | -) -> Union[Weaviate, VertexFeatureStore, Pinecone]: | 103 | | - """Convert Gapic RagVectorDbConfig to Weaviate, VertexFeatureStore, or Pinecone.""" | | 103 | +) -> Union[Weaviate, VertexFeatureStore, VertexVectorSearch, Pinecone]: | | 104 | + """Convert Gapic RagVectorDbConfig to Weaviate, VertexFeatureStore, VertexVectorSearch, or Pinecone.""" | 104 | 105 | if gapic_vector_db.__contains__("weaviate"): | 105 | 106 | return Weaviate( | 106 | 107 | weaviate_http_endpoint=gapic_vector_db.weaviate.http_endpoint, | @@ -116,6 +117,11 @@ def convert_gapic_to_vector_db( | 116 | 117 | index_name=gapic_vector_db.pinecone.index_name, | 117 | 118 | api_key=gapic_vector_db.api_auth.api_key_config.api_key_secret_version, | 118 | 119 | ) | | 120 | + elif gapic_vector_db.__contains__("vertex_vector_search"): | | 121 | + return VertexVectorSearch( | | 122 | + index_endpoint=gapic_vector_db.vertex_vector_search.index_endpoint, | | 123 | + index=gapic_vector_db.vertex_vector_search.index, | | 124 | + ) | 119 | 125 | else: | 120 | 126 | return None | 121 | 127 |
| @@ -418,7 +424,7 @@ def set_embedding_model_config( | 418 | 424 |
| 419 | 425 |
| 420 | 426 | def set_vector_db( | 421 | | - vector_db: Union[Weaviate, VertexFeatureStore, Pinecone], | | 427 | + vector_db: Union[Weaviate, VertexFeatureStore, VertexVectorSearch, Pinecone], | 422 | 428 | rag_corpus: GapicRagCorpus, | 423 | 429 | ) -> None: | 424 | 430 | """Sets the vector db configuration for the rag corpus.""" | @@ -446,6 +452,16 @@ def set_vector_db( | 446 | 452 | feature_view_resource_name=resource_name, | 447 | 453 | ), | 448 | 454 | ) | | 455 | + elif isinstance(vector_db, VertexVectorSearch): | | 456 | + index_endpoint = vector_db.index_endpoint | | 457 | + index = vector_db.index | | 458 | + | | 459 | + rag_corpus.rag_vector_db_config = RagVectorDbConfig( | | 460 | + vertex_vector_search=RagVectorDbConfig.VertexVectorSearch( | | 461 | + index_endpoint=index_endpoint, | | 462 | + index=index, | | 463 | + ), | | 464 | + ) | 449 | 465 | elif isinstance(vector_db, Pinecone): | 450 | 466 | index_name = vector_db.index_name | 451 | 467 | api_key = vector_db.api_key | @@ -462,5 +478,5 @@ def set_vector_db( | 462 | 478 | ) | 463 | 479 | else: | 464 | 480 | raise TypeError( | 465 | | - "vector_db must be a Weaviate, VertexFeatureStore, or Pinecone." | | 481 | + "vector_db must be a Weaviate, VertexFeatureStore, VertexVectorSearch, or Pinecone." | 466 | 482 | ) |
Collapse file Copy file name to clipboardExpand all lines: vertexai/preview/rag/utils/resources.py +20-1Lines changed: 20 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,6 +98,23 @@ class VertexFeatureStore: | 98 | 98 | resource_name: str | 99 | 99 |
| 100 | 100 |
| | 101 | +@dataclasses.dataclass | | 102 | +class VertexVectorSearch: | | 103 | + """VertexVectorSearch. | | 104 | +
| | 105 | + Attributes: | | 106 | + index_endpoint (str): | | 107 | + The resource name of the Index Endpoint. Format: | | 108 | + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` | | 109 | + index (str): | | 110 | + The resource name of the Index. Format: | | 111 | + ``projects/{project}/locations/{location}/indexes/{index}`` | | 112 | + """ | | 113 | + | | 114 | + index_endpoint: str | | 115 | + index: str | | 116 | + | | 117 | + | 101 | 118 | @dataclasses.dataclass | 102 | 119 | class Pinecone: | 103 | 120 | """Pinecone. | @@ -129,7 +146,9 @@ class RagCorpus: | 129 | 146 | display_name: Optional[str] = None | 130 | 147 | description: Optional[str] = None | 131 | 148 | embedding_model_config: Optional[EmbeddingModelConfig] = None | 132 | | - vector_db: Optional[Union[Weaviate, VertexFeatureStore, Pinecone]] = None | | 149 | + vector_db: Optional[ | | 150 | + Union[Weaviate, VertexFeatureStore, VertexVectorSearch, Pinecone] | | 151 | + ] = None | 133 | 152 |
| 134 | 153 |
| 135 | 154 | @dataclasses.dataclass | |
|