Skip to main content

An integration of Upstash Vector with Haystack.

Project description

upstash-haystack

PyPI - Version PyPI - Python Version CI License

Upstash Vector integration for Haystack — serverless, scalable vector search with zero infrastructure.


Overview

upstash-haystack brings Upstash Vector into the Haystack ecosystem. Upstash Vector is a serverless, pay-as-you-go vector database with a generous free tier — no servers to provision, no clusters to manage.

Components

Component Description
UpstashDocumentStore Full-featured document store backed by Upstash Vector
UpstashEmbeddingRetriever Dense retrieval using cosine/dot-product similarity
UpstashHybridRetriever Dense + sparse hybrid search via native Reciprocal Rank Fusion (RRF)

Installation

pip install upstash-haystack

Quick Start

1. Create an Upstash Vector index

Sign up at console.upstash.com and create a Vector index. Copy the REST URL and REST Token from the dashboard.

export UPSTASH_VECTOR_REST_URL="https://your-endpoint.upstash.io"
export UPSTASH_VECTOR_REST_TOKEN="your-token"

2. Dense (Embedding) Retrieval

from haystack import Document, Pipeline
from haystack_integrations.document_stores.upstash import UpstashDocumentStore
from haystack_integrations.components.retrievers.upstash import UpstashEmbeddingRetriever

# Initialize the document store (reads credentials from env vars)
document_store = UpstashDocumentStore()

# Write documents with embeddings
docs = [
    Document(content="The capital of France is Paris.", embedding=[0.1, 0.2, ...]),
    Document(content="The capital of Germany is Berlin.", embedding=[0.4, 0.5, ...]),
]
document_store.write_documents(docs)

# Retrieve the top-k most similar documents
retriever = UpstashEmbeddingRetriever(document_store=document_store)
result = retriever.run(query_embedding=[0.1, 0.2, ...], top_k=1)
print(result["documents"])

3. Hybrid Retrieval (Dense + Sparse)

Upstash Vector natively supports hybrid search via Reciprocal Rank Fusion (RRF), combining dense and sparse signals for superior relevance.

from haystack.dataclasses import SparseEmbedding
from haystack_integrations.components.retrievers.upstash import UpstashHybridRetriever

retriever = UpstashHybridRetriever(document_store=document_store)

result = retriever.run(
    query_embedding=[0.1, 0.2, ...],
    query_sparse_embedding=SparseEmbedding(indices=[0, 5, 12], values=[0.9, 0.4, 0.2]),
    top_k=5,
)
print(result["documents"])

4. Filtering

# Equality filter
docs = document_store.filter_documents(filters={"field": "meta.category", "operator": "==", "value": "science"})

# AND operator
docs = document_store.filter_documents(
    filters={
        "operator": "AND",
        "conditions": [
            {"field": "meta.category", "operator": "==", "value": "science"},
            {"field": "meta.year", "operator": ">", "value": 2020},
        ],
    }
)

Configuration

The document store is configured via environment variables or explicit Secret objects:

from haystack.utils.auth import Secret
from haystack_integrations.document_stores.upstash import UpstashDocumentStore

store = UpstashDocumentStore(
    url=Secret.from_env_var("UPSTASH_VECTOR_REST_URL"),
    token=Secret.from_env_var("UPSTASH_VECTOR_REST_TOKEN"),
)

Development

This project uses Hatch for environment and dependency management.

# Format and lint
hatch run fmt

# Type checking
hatch run test:types

# Unit tests (mocked, no credentials needed)
hatch run test:unit

# Integration tests (requires live Upstash credentials)
export UPSTASH_VECTOR_REST_URL="..."
export UPSTASH_VECTOR_REST_TOKEN="..."
hatch run test:integration

License

upstash-haystack is distributed under the terms of the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

upstash_haystack-0.1.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

upstash_haystack-0.1.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file upstash_haystack-0.1.1.tar.gz.

File metadata

  • Download URL: upstash_haystack-0.1.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.10.20"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.10.20","system":{"name":"Linux","release":"6.17.0-1020-azure"}} HTTPX2/2.9.1

File hashes

Hashes for upstash_haystack-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6ecc941c064af5993618d62890a9de2dc46fb9806ed4384fc40ae4339a6e3a11
MD5 6918d800969b8db2ddb1d7edb2b203d8
BLAKE2b-256 8df1c31dda35850c42900512065eea94e5b7b71fca19799fa9a0d944a683b7d4

See more details on using hashes here.

File details

Details for the file upstash_haystack-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: upstash_haystack-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.1 {"ci":true,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.10.20"},"installer":{"name":"hatch","version":"1.17.1"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.10.20","system":{"name":"Linux","release":"6.17.0-1020-azure"}} HTTPX2/2.9.1

File hashes

Hashes for upstash_haystack-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a589322e657dac8a988e5b583075b2551b527bd97e5943b21bc485800b0f5bb2
MD5 8afffcc12a77fe6ac6a2a64e9df4e12c
BLAKE2b-256 6cf92c7e55a7723862af9deb73e5536f92a2a2890887cda0ff58b92c992ba373

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page