Integrations

LlamaParse with Upstash Vector

You can use LlamaParse with Upstash Vector to parse documents and perform semantic queries on the content. LlamaParse simplifies the extraction of structured information from files, which can then be indexed and queried using Upstash Vector.

Install

pip install llama-index upstash-vector llama-index-vector-stores-upstash python-dotenv

Setup

Create a Vector Index in the Upstash Console. Set the index with:

  • Dimensions: 1536
  • Distance Metric: Cosine

Add the required environment variables to a .env file:

UPSTASH_VECTOR_REST_URL=your_upstash_urlUPSTASH_VECTOR_REST_TOKEN=your_upstash_tokenLLAMA_CLOUD_API_KEY=your_llama_cloud_api_key

Usage

Parsing Documents

Use LlamaParse to parse a document. For example:

from llama_parse import LlamaParsefrom llama_index.core import SimpleDirectoryReader# Initialize the parserparser = LlamaParse(result_type="markdown")# Parse a documentfile_extractor = {".txt": parser}documents = SimpleDirectoryReader(    input_files=["./documents/global_warming.txt"],    file_extractor=file_extractor).load_data()

Querying the Parsed Content

Once the document is parsed, you can index it using Upstash Vector and query its content:

from llama_index.core import VectorStoreIndexfrom llama_index.vector_stores.upstash import UpstashVectorStorefrom llama_index.core import StorageContextfrom dotenv import load_dotenvimport os# Load environment variablesload_dotenv()# Set up Upstash Vector Storevector_store = UpstashVectorStore(    url=os.getenv("UPSTASH_VECTOR_REST_URL"),    token=os.getenv("UPSTASH_VECTOR_REST_TOKEN"))# Create storage context and index the parsed documentstorage_context = StorageContext.from_defaults(vector_store=vector_store)index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)# Perform a queryquery_engine = index.as_query_engine()response = query_engine.query("What is the main topic discussed in the document?")

To learn more, visit the LlamaParse documentation.

Loading search…