I’m trying to build a RAG system using a vector search index from GCP services on Python.
I have already created the vector search index and deployed the endpoint. Im using below code:
<code>from langchain_google_vertexai import (
VectorSearchVectorStore,
VectorSearchVectorStoreDatastore,
)
# TODO : replace 1234567890123456789 with your acutial index ID
my_index = aiplatform.MatchingEngineIndex("1234567890123456789")
# TODO : replace 1234567890123456789 with your acutial endpoint ID
my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint("1234567890123456789")
# Input texts
chunk_texts= [
"The cat sat on",
"the mat.",
"I like to",
"eat pizza for",
"dinner.",
"The sun sets",
"in the west.",
]
# Create a Vector Store
vector_store = VectorSearchVectorStore.from_components(
project_id=PROJECT_ID,
region=REGION,
gcs_bucket_name=BUCKET,
index_id=my_index.name,
endpoint_id=my_index_endpoint.name,
embedding=embedding_model,
stream_update=True,
)
# Add vectors and mapped text chunks to your vectore store
vector_store.add_texts(texts=chunk_texts,is_complete_overwrite=True)
</code>
<code>from langchain_google_vertexai import (
VectorSearchVectorStore,
VectorSearchVectorStoreDatastore,
)
# TODO : replace 1234567890123456789 with your acutial index ID
my_index = aiplatform.MatchingEngineIndex("1234567890123456789")
# TODO : replace 1234567890123456789 with your acutial endpoint ID
my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint("1234567890123456789")
# Input texts
chunk_texts= [
"The cat sat on",
"the mat.",
"I like to",
"eat pizza for",
"dinner.",
"The sun sets",
"in the west.",
]
# Create a Vector Store
vector_store = VectorSearchVectorStore.from_components(
project_id=PROJECT_ID,
region=REGION,
gcs_bucket_name=BUCKET,
index_id=my_index.name,
endpoint_id=my_index_endpoint.name,
embedding=embedding_model,
stream_update=True,
)
# Add vectors and mapped text chunks to your vectore store
vector_store.add_texts(texts=chunk_texts,is_complete_overwrite=True)
</code>
from langchain_google_vertexai import (
VectorSearchVectorStore,
VectorSearchVectorStoreDatastore,
)
# TODO : replace 1234567890123456789 with your acutial index ID
my_index = aiplatform.MatchingEngineIndex("1234567890123456789")
# TODO : replace 1234567890123456789 with your acutial endpoint ID
my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint("1234567890123456789")
# Input texts
chunk_texts= [
"The cat sat on",
"the mat.",
"I like to",
"eat pizza for",
"dinner.",
"The sun sets",
"in the west.",
]
# Create a Vector Store
vector_store = VectorSearchVectorStore.from_components(
project_id=PROJECT_ID,
region=REGION,
gcs_bucket_name=BUCKET,
index_id=my_index.name,
endpoint_id=my_index_endpoint.name,
embedding=embedding_model,
stream_update=True,
)
# Add vectors and mapped text chunks to your vectore store
vector_store.add_texts(texts=chunk_texts,is_complete_overwrite=True)
Full Error:
<code>AttributeError Traceback (most recent call last)
<ipython-input-22-5aa9b7d77460> in <cell line: 19>()
17
18 # Add vectors and mapped text chunks to your vectore store
---> 19 vector_store.add_texts(texts=text_chunks,is_complete_overwrite=True)
3 frames
/usr/local/lib/python3.10/dist-packages/langchain_google_vertexai/vectorstores/vectorstores.py in add_texts(self, texts, metadatas, is_complete_overwrite, **kwargs)
198 ]
199
--> 200 self._document_storage.mset(list(zip(ids, documents)))
201
202 embeddings = self._embeddings.embed_documents(texts)
/usr/local/lib/python3.10/dist-packages/langchain_google_vertexai/vectorstores/document_storage.py in mset(self, key_value_pairs)
98 # the input list, in order.
99 if isinstance(result, Exception):
--> 100 raise result
101 else:
102 for key, value in key_value_pairs:
/usr/lib/python3.10/concurrent/futures/thread.py in run(self)
56
57 try:
---> 58 result = self.fn(*self.args, **self.kwargs)
59 except BaseException as exc:
60 self.future.set_exception(exc)
/usr/local/lib/python3.10/dist-packages/google/cloud/storage/transfer_manager.py in _call_method_on_maybe_pickled_blob(maybe_pickled_blob, method_name, *args, **kwargs)
1276 else:
1277 blob = pickle.loads(maybe_pickled_blob)
-> 1278 return getattr(blob, method_name)(*args, **kwargs)
1279
1280
AttributeError: 'Blob' object has no attribute '_prep_and_do_upload'
</code>
<code>AttributeError Traceback (most recent call last)
<ipython-input-22-5aa9b7d77460> in <cell line: 19>()
17
18 # Add vectors and mapped text chunks to your vectore store
---> 19 vector_store.add_texts(texts=text_chunks,is_complete_overwrite=True)
3 frames
/usr/local/lib/python3.10/dist-packages/langchain_google_vertexai/vectorstores/vectorstores.py in add_texts(self, texts, metadatas, is_complete_overwrite, **kwargs)
198 ]
199
--> 200 self._document_storage.mset(list(zip(ids, documents)))
201
202 embeddings = self._embeddings.embed_documents(texts)
/usr/local/lib/python3.10/dist-packages/langchain_google_vertexai/vectorstores/document_storage.py in mset(self, key_value_pairs)
98 # the input list, in order.
99 if isinstance(result, Exception):
--> 100 raise result
101 else:
102 for key, value in key_value_pairs:
/usr/lib/python3.10/concurrent/futures/thread.py in run(self)
56
57 try:
---> 58 result = self.fn(*self.args, **self.kwargs)
59 except BaseException as exc:
60 self.future.set_exception(exc)
/usr/local/lib/python3.10/dist-packages/google/cloud/storage/transfer_manager.py in _call_method_on_maybe_pickled_blob(maybe_pickled_blob, method_name, *args, **kwargs)
1276 else:
1277 blob = pickle.loads(maybe_pickled_blob)
-> 1278 return getattr(blob, method_name)(*args, **kwargs)
1279
1280
AttributeError: 'Blob' object has no attribute '_prep_and_do_upload'
</code>
AttributeError Traceback (most recent call last)
<ipython-input-22-5aa9b7d77460> in <cell line: 19>()
17
18 # Add vectors and mapped text chunks to your vectore store
---> 19 vector_store.add_texts(texts=text_chunks,is_complete_overwrite=True)
3 frames
/usr/local/lib/python3.10/dist-packages/langchain_google_vertexai/vectorstores/vectorstores.py in add_texts(self, texts, metadatas, is_complete_overwrite, **kwargs)
198 ]
199
--> 200 self._document_storage.mset(list(zip(ids, documents)))
201
202 embeddings = self._embeddings.embed_documents(texts)
/usr/local/lib/python3.10/dist-packages/langchain_google_vertexai/vectorstores/document_storage.py in mset(self, key_value_pairs)
98 # the input list, in order.
99 if isinstance(result, Exception):
--> 100 raise result
101 else:
102 for key, value in key_value_pairs:
/usr/lib/python3.10/concurrent/futures/thread.py in run(self)
56
57 try:
---> 58 result = self.fn(*self.args, **self.kwargs)
59 except BaseException as exc:
60 self.future.set_exception(exc)
/usr/local/lib/python3.10/dist-packages/google/cloud/storage/transfer_manager.py in _call_method_on_maybe_pickled_blob(maybe_pickled_blob, method_name, *args, **kwargs)
1276 else:
1277 blob = pickle.loads(maybe_pickled_blob)
-> 1278 return getattr(blob, method_name)(*args, **kwargs)
1279
1280
AttributeError: 'Blob' object has no attribute '_prep_and_do_upload'
langchain_google_vertexai == 1.0.10
The pipeline works when I create a new vector search and deploy a new endpoint, but I encounter an error when attempting to use it from a prebuilt ID.
2