Skip to main content

An HTTP/REST based AI Search client built on top of Upstash REST API.

Project description

Upstash AI Search Python Client

[!NOTE] This project is in GA Stage.

The Upstash Professional Support fully covers this project. It receives regular updates, and bug fixes. The Upstash team is committed to maintaining and improving its functionality.

It is a connectionless (HTTP based) AI Search client and designed for:

  • Serverless functions (AWS Lambda ...)
  • Cloudflare Workers
  • Next.js, Jamstack ...
  • Client side web/mobile applications
  • WebAssembly
  • and other environments where HTTP is preferred over TCP.

Quick Start

Install

Python

pip install upstash-search

Create Database

Create a new database on Upstash

Basic Usage:

from upstash_search import Search

client = Search(
    url="<UPSTASH_SEARCH_REST_URL>",
    token="<UPSTASH_SEARCH_REST_TOKEN>",
)

# Access the index of a database
index = client.index("movies")

# Upsert documents into index
index.upsert(
    documents=[
        {
            "id": "movie-0",
            "content": {
                "title": "Star Wars",
                "overview": "Sci-fi space opera",
                "genre": "sci-fi",
                "category": "classic",
            },
            "metadata": {
                "poster": "https://poster.link/starwars.jpg",
            },
        },
        {
            "id": "movie-1",
            "content": {
                "title": "Inception",
                "overview": "Mind-bending thriller",
                "genre": "sci-fi",
                "category": "modern",
            },
            "metadata": {
                "poster": "https://poster.link/inception.jpg",
            },
        },
    ],
)

# Fetch documents by ids
documents = index.fetch(
    ids=["movie-0", "movie-1"],
)
print(documents)

# AI search
scores = index.search(
    query="space opera",
    limit=2,
)
print(scores)

# AI search with reranking
scores = index.search(
    query="space opera",
    limit=2,
    reranking=True
)
print(scores)

# AI search with only semantic search
scores = index.search(
  query="space opera",
  limit=2,
  semantic_weight=1
)

# AI search with only full-text search
scores = index.search(
  query="space opera",
  limit=2,
  semantic_weight=0
)

# AI search with full-text search and sematic search
# combined with equal weights
scores = index.search(
  query="space opera",
  limit=2,
  semantic_weight=0.5
)

# AI search without input enrichment
scores = index.search(
  query="space opera",
  limit=2,
  input_enrichment=False
)

# AI search with filtering
scores = index.search(
    query="space opera",
    limit=2,
    filter="category = 'classic'",
)
print(scores)

# Range over documents
range_documents = index.range(
    cursor="",
    limit=1,
)
print(range_documents.documents)

# Range over the next page of documents
range_documents = index.range(
    cursor=range_documents.next_cursor,
    limit=3,
)

# Delete a document by id
index.delete(
    ids=["movie-0"],
)

# Reset the index (delete all documents)
index.reset()

# Get database and index info
info = client.info()
print(info)

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_search-0.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

upstash_search-0.1.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: upstash_search-0.1.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.8.18 Linux/6.11.0-1018-azure

File hashes

Hashes for upstash_search-0.1.1.tar.gz
Algorithm Hash digest
SHA256 83251e642188a26150b0bb2ac0fdfb72420064404e04ff539cc3b797561ac806
MD5 9b29e4919e92c48af4dda76a273b3e0f
BLAKE2b-256 364cfbc25cb531ac5566a533347d83ab691cd125455e5801cc8045fd6641552c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: upstash_search-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.8.18 Linux/6.11.0-1018-azure

File hashes

Hashes for upstash_search-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd7126ff6e2d852eb0a2cc6d24825521bf883d9c74784ac27dd5f4d6bf9e249b
MD5 27402c709d5eafd26be2a3c0fae0c22c
BLAKE2b-256 7a44aa151c17ea1e76eaf7ee215ade8a0308388330f55fd615fa92bfcc49bdaf

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