Open In Colab

Metal Vector Store#

Creating a Metal Vector Store#

  1. Register an account for Metal

  2. Generate an API key in Metal’s Settings. Save the api_key + client_id

  3. Generate an Index in Metal’s Dashboard. Save the index_id

Load data into your Index#

%pip install llama-index-vector-stores-metal
import logging
import sys

logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores.metal import MetalVectorStore
from IPython.display import Markdown, display

Download Data

!mkdir -p 'data/paul_graham/'
!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'
# load documents
documents = SimpleDirectoryReader("./data/paul_graham/").load_data()
# initialize Metal Vector Store
from llama_index.core import StorageContext

api_key = "api key"
client_id = "client id"
index_id = "index id"

vector_store = MetalVectorStore(
    api_key=api_key,
    client_id=client_id,
    index_id=index_id,
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
    documents, storage_context=storage_context
)

Query Index#

# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
display(Markdown(f"<b>{response}</b>"))