Install
Setup
Create a Vector Index in the Upstash Console. Set the index with:- Dimensions: 1536
- Distance Metric: Cosine
.env file:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
pip install llama-index upstash-vector llama-index-vector-stores-upstash python-dotenv
.env file:
UPSTASH_VECTOR_REST_URL=your_upstash_url
UPSTASH_VECTOR_REST_TOKEN=your_upstash_token
LLAMA_CLOUD_API_KEY=your_llama_cloud_api_key
from llama_parse import LlamaParse
from llama_index.core import SimpleDirectoryReader
# Initialize the parser
parser = LlamaParse(result_type="markdown")
# Parse a document
file_extractor = {".txt": parser}
documents = SimpleDirectoryReader(
input_files=["./documents/global_warming.txt"],
file_extractor=file_extractor
).load_data()
from llama_index.core import VectorStoreIndex
from llama_index.vector_stores.upstash import UpstashVectorStore
from llama_index.core import StorageContext
from dotenv import load_dotenv
import os
# Load environment variables
load_dotenv()
# Set up Upstash Vector Store
vector_store = UpstashVectorStore(
url=os.getenv("UPSTASH_VECTOR_REST_URL"),
token=os.getenv("UPSTASH_VECTOR_REST_TOKEN")
)
# Create storage context and index the parsed document
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
# Perform a query
query_engine = index.as_query_engine()
response = query_engine.query("What is the main topic discussed in the document?")
Was this page helpful?