import logging
import os
import socket
import tempfile
from pathlib import Path
import boto3
from moto.server import ThreadedMotoServer
import jammi
from jammi_cookbook import fixtures
os.environ.setdefault("JAMMI_GPU__DEVICE", "-1")
os.environ.setdefault("JAMMI_ENGINE__BATCH_SIZE", "8")
CORPUS = fixtures.path("tiny_corpus.parquet")
MODEL = fixtures.model("tiny_bert")
BUCKET = "jammi-cookbook"
QUERY = "how does quantum computing work?"42 Cloud object storage from the embedded engine
Read a source straight out of an S3 bucket and write every result table the session produces — its Parquet and its ANN index segments — back into the bucket, from jammi.connect("file://…"). The embedded engine speaks the same s3:// / gs:// / azure:// / r2:// URLs a jammi-server does.
When to use this pattern. Your data already lives in object storage, or the results must outlive the machine that computed them — a notebook runtime, a batch job on a spot instance — without standing up a server.
42.1 The configuration
[storage]
result_root = "s3://jammi-cookbook/results"
[storage.cloud.s3]
region = "us-east-1"
endpoint = "http://127.0.0.1:<port>" # a local S3-compatible server only
allow_http = true # a local S3-compatible server onlyPass it as jammi.connect("file:///var/lib/jammi", config="jammi.toml"). The keys come from the environment (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY), or from the SDK’s credential chain against real S3. See Store Sources and Results in Cloud Object Storage.
42.2 API surface exercised
jammi.connect("file://…", config=…)with a[storage]sectionSession.add_source(name, url="s3://…", format="parquet")Session.generate_embeddings(...),encode_query(...),search(...)
The program is cookbook/recipes/cloud_storage/example.py; its steps run here in order.
The embedded engine speaks the same storage URLs a server does. A source registered at an s3:// URL is read through the S3 driver, and a [storage] result_root on s3:// puts every result table the session writes, its Parquet and its ANN index segments, in the bucket instead of on local disk.
This program serves S3 locally from moto, an S3-compatible server, and runs one search twice: over local disk, then with both the corpus and the results in a bucket. The local run is the reference the bucket run must match.
42.3 Serve S3 locally and fill a bucket
The S3 driver reads its keys from the environment, as it does against real S3. Against real S3, the SDK’s credential chain (environment variables, an instance profile, …) supplies them.
with socket.socket() as probe:
probe.bind(("127.0.0.1", 0))
port = probe.getsockname()[1]
endpoint = f"http://127.0.0.1:{port}"
os.environ.update(
AWS_ACCESS_KEY_ID="cookbook", AWS_SECRET_ACCESS_KEY="cookbook", AWS_REGION="us-east-1"
)
# The local S3 server logs every request; this program's own output is the story.
logging.getLogger("werkzeug").setLevel(logging.ERROR)
server = ThreadedMotoServer(ip_address="127.0.0.1", port=port)
server.start()
s3 = boto3.client("s3", endpoint_url=endpoint, region_name="us-east-1")
s3.create_bucket(Bucket=BUCKET)
s3.upload_file(str(CORPUS), BUCKET, "sources/tiny_corpus.parquet")Starting a new Thread with MotoServer running on 127.0.0.1:36467...
42.4 One program, wherever its data lives
Register the corpus at a URL, embed it, search it, and return the ranked (_row_id, similarity) pairs.
def search_rows(target_dir: str, *, corpus_url: str, config: Path | None) -> list[tuple]:
with jammi.connect(f"file://{target_dir}", config=str(config) if config else None) as db:
db.add_source("corpus", url=corpus_url, format="parquet")
db.generate_embeddings(
source="corpus", model=MODEL, columns=["content"], key="id", modality="text"
)
query = db.encode_query(model=MODEL, query=QUERY)
hits = db.search("corpus", query=query, k=5).to_pylist()
return [(row["_row_id"], round(row["similarity"], 6)) for row in hits]
golden = search_rows(tempfile.mkdtemp(), corpus_url=str(CORPUS), config=None)
print(f"top-5 over local disk: {golden}")top-5 over local disk: [('15', 0.935367), ('11', 0.929288), ('1', 0.926265), ('7', 0.9203), ('2', 0.919876)]
2026-10-03T07:47:27.888727Z WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"
42.5 Run it against the bucket
Where results go, and how to reach the store, is deployment configuration: the same [storage] section a server reads. Against real S3, drop the endpoint and allow_http lines.
cloud = Path(tempfile.mkdtemp())
config = cloud / "jammi.toml"
config.write_text(
f'[storage]\nresult_root = "s3://{BUCKET}/results"\n\n'
f'[storage.cloud.s3]\nregion = "us-east-1"\nendpoint = "{endpoint}"\n'
"allow_http = true\n"
)
from_s3 = search_rows(
str(cloud), corpus_url=f"s3://{BUCKET}/sources/tiny_corpus.parquet", config=config
)
print(f"top-5 over s3://{BUCKET}: {from_s3}")
assert from_s3 == golden, f"the S3 run ranked differently: {from_s3} vs {golden}"top-5 over s3://jammi-cookbook: [('15', 0.935367), ('11', 0.929288), ('1', 0.926265), ('7', 0.9203), ('2', 0.919876)]
42.6 The results are in the bucket
The result table’s Parquet and its index segments were written under the bucket’s results/ prefix.
objects = [o["Key"] for o in s3.list_objects_v2(Bucket=BUCKET)["Contents"]]
server.stop()
results = sorted(key for key in objects if key.startswith("results/"))
for key in results:
print(f"s3://{BUCKET}/{key}")
assert any(key.endswith(".parquet") for key in results), results
assert any(key.endswith(".usearch") for key in results), resultss3://jammi-cookbook/results/_global/corpus__text_embedding_____w_jammi-ai_jammi-ai_cookbook_book_jammi_cookbook__fixtures_ti__20261003T074728010502299_5e437b0a.materialization.json
s3://jammi-cookbook/results/_global/corpus__text_embedding_____w_jammi-ai_jammi-ai_cookbook_book_jammi_cookbook__fixtures_ti__20261003T074728010502299_5e437b0a.parquet
s3://jammi-cookbook/results/_global/corpus__text_embedding_____w_jammi-ai_jammi-ai_cookbook_book_jammi_cookbook__fixtures_ti__20261003T074728010502299_5e437b0a__seg0.manifest.json
s3://jammi-cookbook/results/_global/corpus__text_embedding_____w_jammi-ai_jammi-ai_cookbook_book_jammi_cookbook__fixtures_ti__20261003T074728010502299_5e437b0a__seg0.rowmap
s3://jammi-cookbook/results/_global/corpus__text_embedding_____w_jammi-ai_jammi-ai_cookbook_book_jammi_cookbook__fixtures_ti__20261003T074728010502299_5e437b0a__seg0.usearch