Back to Llama Index

DashVector Vector Store

docs/examples/vector_stores/DashvectorIndexDemo.ipynb

0.14.212.1 KB
Original Source

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/vector_stores/DashvectorIndexDemo.ipynb" target="_parent"></a>

DashVector Vector Store

If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.

python
%pip install llama-index-vector-stores-dashvector
python
!pip install llama-index
python
import logging
import sys
import os

logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))

Creating a DashVector Collection

python
import dashvector
python
api_key = os.environ["DASHVECTOR_API_KEY"]
client = dashvector.Client(api_key=api_key)
python
# dimensions are for text-embedding-ada-002
client.create("llama-demo", dimension=1536)
python
dashvector_collection = client.get("quickstart")

Download Data

python
!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, build the DashVectorStore and VectorStoreIndex

python
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores.dashvector import DashVectorStore
from IPython.display import Markdown, display
python
# load documents
documents = SimpleDirectoryReader("./data/paul_graham").load_data()
python
# initialize without metadata filter
from llama_index.core import StorageContext

vector_store = DashVectorStore(dashvector_collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
    documents, storage_context=storage_context
)

Query Index

python
# 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?")
python
display(Markdown(f"<b>{response}</b>"))