Skip to main content

Mojo-first late-interaction retrieval engine

Project description

Kayak Python SDK

kayak is a Python SDK for late-interaction retrieval.

It gives you explicit objects for:

  • queries
  • documents
  • packed indexes
  • MaxSim scores
  • top-k search hits

The API is designed to feel natural for NumPy and PyTorch users without hiding the parts that matter in late interaction:

  • query vector count stays explicit
  • document vector count stays explicit
  • layout stays explicit
  • backend choice stays explicit

Install

With pip:

pip install kayak

With UV:

uv add kayak

With Pixi and PyPI:

pixi add --pypi kayak

Optional Mojo Backend

The default Python SDK path uses the NumPy reference backend.

The Python package does not expose a separate "Mojo-mode" import surface. You still write normal Python:

  • import kayak
  • build query, documents, and index
  • opt into the Mojo backend explicitly on the operation call

You only need Mojo if you want the explicit exact CPU Mojo backend:

  • kayak.MOJO_EXACT_CPU_BACKEND

Examples:

# global or activated environment
pip install kayak
mojo --version
# Pixi project
pixi add python=3.11 mojo
pixi add --pypi kayak
pixi run python app.py

Then select the backend explicitly:

scores = kayak.maxsim(
    query,
    index,
    backend=kayak.MOJO_EXACT_CPU_BACKEND,
)

Kayak does not silently switch to the Mojo backend just because Mojo is installed. The backend choice stays explicit.

If you are running inside an activated virtual environment or pixi run python, Kayak first checks that active Python environment for a usable mojo binary before falling back to PATH.

Current CLI discovery order for the Mojo backend:

  • KAYAK_MOJO_CLI
  • a usable mojo binary in the active Python environment
  • mojo on PATH
  • pixi run mojo

If you do not pass backend=kayak.MOJO_EXACT_CPU_BACKEND, Kayak stays on the NumPy reference backend and does not require Mojo.

Core API

Create a query:

import kayak
import numpy as np

query = kayak.query(
    np.array(
        [
            [1.0, 0.0],
            [0.0, 1.0],
        ],
        dtype=np.float32,
    )
)

Create a document collection:

documents = kayak.documents(
    ["doc-a", "doc-b"],
    [
        np.array([[1.0, 0.0], [0.0, 1.0]], dtype=np.float32),
        np.array([[1.0, 0.0], [0.5, 0.5]], dtype=np.float32),
    ],
)

Pack documents into an index:

index = documents.pack()

Score with MaxSim:

scores = kayak.maxsim(query, index)

Search:

hits = kayak.search(query, index, k=2)

Layouts

Kayak keeps layout changes explicit.

flat_dim128 and hybrid_flat_dim128 require vector_dim == 128.

Example:

import kayak
import numpy as np

def dim128(index: int) -> np.ndarray:
    vector = np.zeros(128, dtype=np.float32)
    vector[index] = 1.0
    return vector

query128 = kayak.query(np.stack([dim128(0), dim128(1)]))
documents128 = kayak.documents(
    ["doc-a", "doc-b"],
    [
        np.stack([dim128(0), dim128(1)]),
        np.stack([dim128(0), dim128(0)]),
    ],
)
index128 = documents128.pack()

flat_query = query128.to_layout("flat_dim128")
hybrid_index = index128.to_layout("hybrid_flat_dim128")

scores = kayak.maxsim(flat_query, hybrid_index)

Backends

The package exposes two named backends:

  • kayak.NUMPY_REFERENCE_BACKEND
  • kayak.MOJO_EXACT_CPU_BACKEND

Example:

scores = kayak.maxsim(
    query,
    index,
    backend=kayak.NUMPY_REFERENCE_BACKEND,
)

The NumPy backend is the safest default.

The Mojo exact CPU backend is the faster exact path when your environment has a working Mojo installation:

scores = kayak.maxsim(
    query,
    index,
    backend=kayak.MOJO_EXACT_CPU_BACKEND,
)

Public Surface

Application code should import from kayak.

Main exports:

  • LateQuery
  • LateDocuments
  • LateIndex
  • LateScores
  • SearchHit
  • query
  • documents
  • packed_index
  • hybrid_flat_dim128_index
  • flat_query_dim128
  • maxsim
  • search

Mental Model

Kayak is not a generic tensor library.

It is a late-interaction retrieval API with:

  • ragged query and document vector counts
  • explicit layout conversion
  • exact MaxSim scoring
  • explicit search backends

That makes it suitable for code that wants retrieval semantics first, while still fitting naturally into Python workflows built on NumPy or PyTorch.

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

kayak-0.1.3.tar.gz (77.9 kB view details)

Uploaded Source

Built Distribution

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

kayak-0.1.3-py3-none-any.whl (2.4 MB view details)

Uploaded Python 3

File details

Details for the file kayak-0.1.3.tar.gz.

File metadata

  • Download URL: kayak-0.1.3.tar.gz
  • Upload date:
  • Size: 77.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.16

File hashes

Hashes for kayak-0.1.3.tar.gz
Algorithm Hash digest
SHA256 da60f67dea6ca1731c5ad6c1ee903ff15487fc5c54322e30149d4028e7d03736
MD5 459e99fa8d6b1e9311c777e0bd0052cc
BLAKE2b-256 c1931e5111ea5a47b66b8e21c24ed17ee4ee918ffdfa73af447084a81ff90927

See more details on using hashes here.

File details

Details for the file kayak-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: kayak-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.16

File hashes

Hashes for kayak-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 afab8d43447c3128e84f4eed663df6ba40ef56a9e8301d7d1f306f59a0144866
MD5 b50305b685dc44c776fd2b47f29a90e5
BLAKE2b-256 fff740e115447bb4cdd2730918a290bd90199c97b12616a9e621ad3218502b5b

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