VectorIndexes¶
Note
The VectorIndexes class primarily focuses on the creation of an asset, assuming the vector index already exists externally. Additional steps (such as parsing documents, splitting them into chunks, creating embeddings, and uploading them to the external vector database) are required to ensure functionality in the absence of aforementioned vector index in the external vector store.
- class ibm_watsonx_ai.foundation_models.utils.VectorIndexes(api_client)[source]¶
Bases:
WMLResourceInitiate the Vector Indexes class.
- Parameters:
api_client (APIClient) – instance of APIClient with default project_id set
Example:
vector_indexes = VectorIndexes(api_client=api_client)
- create(name, description=None, store=None, settings=None, tags=None, sample_questions=None, **kwargs)[source]¶
Create a new Vector Index Asset.
- Parameters:
name (str) – name for vector index asset
description (str | None) – optional description for the vector index asset, defaults to None
store (dict | None, optional) – store parameters, defaults to None
settings (dict | None, optional) – settings of vector index, defaults to None
tags (list[str] | None, optional) – tags attached to the asset, defaults to None
sample_questions (list[str] | None, optional) – sample asked questions, defaults to None
data_assets (list[str] | None, optional) – IDs of the associated data assets used in the vector index, defaults to None
build (dict | None, optional) – the associated build to process the data for external vector stores, defaults to None
status (str | None, optional) – the status of the vector index, defaults to None
- Returns:
metadata of the created Vector Index Asset
- Return type:
dict
Example:
params = dict( name="test_sdk_vector_index", description="Description", settings={ "embedding_model_id": "<model_id>", "top_k": 1, "schema_fields": {"text": "text"}, }, store={ "type": "watsonx.data", "connection_id": "<connection_id>", "index": "<index_name>", "new_index": False, "database": "default", }, tags=["test_tag"], sample_questions=["Sample question"], status="ready", ) vector_index_details = vector_indexes.create(**params)
- create_transactional(name, *, description=None, store=None, data_assets=None, settings=None, sample_questions=None)[source]¶
Create a new Vector Index asset using transactional API.
- Parameters:
name (str) – name of the vector index asset
description (str, optional) – description of the vector index asset, defaults to None
store (str | dict, optional) – vector store settings
data_assets (list[str], optional) – IDs of data assets used in the vector index, defaults to None
settings (dict, optional) – settings of vector index, defaults to None
sample_questions (list[str], optional) – sample asked questions, defaults to None
- Returns:
metadata of the created Vector Index asset
- Return type:
dict
Example:
vector_index_details = vector_indexes.create_transactional( "test_sdk_vector_index", description="Description", store={ "type": "watsonx.data", "connection_id": "<connection_id>", "index": "<index_name>", "new_index": False, "database": "default", }, data_assets=[ "713259df-0540-4301-982e-693a81da462c", "713259df-0540-4301-982e-693a81da573d", ], settings={ "embedding_model_id": "<model_id>", "top_k": 1, "schema_fields": {"text": "text"}, }, sample_questions=["summarize the document, name of the author"], )
- delete(index_id)[source]¶
Delete a vector index with the given id.
- Parameters:
index_id (str) – Vector Index id
- Returns:
“SUCCESS” if deletion succeeded
- Return type:
str
- Raises:
WMLClientError – if deletion failed
Example:
vector_indexes.delete(vector_index_id)
- get_details(index_id)[source]¶
Get details of Vector Index Asset with the given ID.
- Parameters:
index_id (str) – ID of the vector index asset
- Returns:
details of the Vector Index Asset with the given ID
- Return type:
dict
Example:
vector_indexes.get_details(index_id)
- get_details_transactional(vector_index_id)[source]¶
Get details of Vector Index asset with the given ID using transactional API.
- Parameters:
vector_index_id (str) – ID of the vector index asset
- Returns:
details of vector index asset with the given ID
- Return type:
dict
Example:
vector_indexes.get_details_transactional(vector_index_id)
- list(*, limit=None)[source]¶
List all available Vector Index assets in the
DataFrameformat.- Parameters:
limit (int, optional) – limit number of fetched records, defaults to None
- Returns:
DataFrameof fundamental properties of available Vector Index assets- Return type:
pandas.DataFrame
Example:
# list of 5 recently created vector index assets df = vector_indexes.list(limit=5)
- update(index_id, name=None, description=None, store=None, settings=None, tags=None, sample_questions=None, **kwargs)[source]¶
Update a Vector Index Asset with the given id.
- Parameters:
index_id (str) – ID of the vector index asset
name (str | None) – name for vector index asset, defaults to None
description (str | None) – optional description for the vector index asset, defaults to None
store (dict | None, optional) – store parameters, defaults to None
settings (dict | None, optional) – settings of vector index, defaults to None
tags (list[str] | None, optional) – tags attached to the asset, defaults to None
sample_questions (list[str] | None, optional) – sample asked questions, defaults to None
data_assets (list[str] | None, optional) – IDs of the associated data assets used in the vector index, defaults to None
build (dict | None, optional) – the associated build to process the data for external vector stores, defaults to None
status (str | None, optional) – the status of the vector index, defaults to None
- Returns:
metadata of the updated Vector Index Asset
- Return type:
dict
Example:
vector_indexes.update( index_id, name="new_name", description="new_description" )
- update_transactional(vector_index_id, *, name=None, description=None, store=None, data_assets=None, settings=None, sample_questions=None, build=None, status=None)[source]¶
Update a Vector Index asset with the given ID using transactional API.
- Parameters:
vector_index_id (str) – ID of the vector index asset
name (str, optional) – name of the vector index asset
description (str, optional) – description of the vector index asset, defaults to None
store (str | dict, optional) – vector store settings
data_assets (list[str], optional) – IDs of data assets used in the vector index, defaults to None
settings (dict, optional) – settings of vector index, defaults to None
sample_questions (list[str], optional) – sample asked questions, defaults to None
build (dict, optional) – the associated build to process the data for external vector stores, defaults to None
status (str, optional) – the status of the vector index, defaults to None
- Returns:
metadata of the updated Vector Index asset
- Return type:
dict
Example:
vector_index_details = vector_indexes.update_transactional( vector_index_id, name="new_vector_index_name", description="new_vector_index_description", )