----------------------
I'm sorry, but the provided extracts do not contain information on how to use a GCP Storage bucket as a filesystem for StorageContext in LlamaIndex. The extracts do provide an example of using an S3 bucket for this purpose, but the process may be different for GCP Storage.
Here's the example for S3:
import dotenv
import s3fs
import os
dotenv.load_dotenv("../../../.env")
# load documents
documents = SimpleDirectoryReader('../../../examples/paul_graham_essay/data/').load_data()
print(len(documents))
index = VectorStoreIndex.from_documents(documents)
# set up s3fs
AWS_KEY = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET = os.environ['AWS_SECRET_ACCESS_KEY']
R2_ACCOUNT_ID = os.environ['R2_ACCOUNT_ID']
assert AWS_KEY is not None and AWS_KEY != ""
s3 = s3fs.S3FileSystem(
key=AWS_KEY,
secret=AWS_SECRET,
endpoint_url=f'<https://{R2_ACCOUNT_ID}.r2.cloudflarestorage.com',>
s3_additional_kwargs={'ACL': 'public-read'}
)
# save index to remote blob storage
index.set_index_id("vector_index")
# this is {bucket_name}/{index_name}
index.storage_context.persist('llama-index/storage_demo', fs=s3)
# load index from s3
sc = StorageContext.from_defaults(persist_dir='llama-index/storage_demo', fs=s3)
index2 = load_index_from_storage(sc, 'vector_index')
(Source:
Persisting & Loading Data ())
For GCP Storage, you would likely need to use a different library that provides a filesystem interface for GCP Storage, similar to how
s3fs
is used for S3 in the example above. However, without specific information in the provided extracts, I can't provide a detailed guide on how to do this.