Skip to main content

BedrockHelper

A small, batteries-included helper for Amazon Bedrock:

  • RAG Q&A using Bedrock Runtime converse / converse_stream when available, with automatic fallback.
  • Embeddings using Titan embed text v2:
    • Small batches inline
    • Large batches via Bedrock batch inference (S3 JSONL)
  • Works in sync and async codebases.
  • Includes a pluggable JobStore abstraction for tracking batch jobs (in-memory, Redis, Postgres, etc.).

Structure

├── .github
│      └── workflows
│          └── mypy.yml
├── .gitignore
├── poetry.lock
├── pyproject.toml
├── README.md
├── src
│    └── bedrockhelper
│          ├── __init__.py
│          ├── batch
│          ├── main.py
│          ├── models.py
│          ├── types.py
│          └── utils.py
└── tests
    ├── test_batch_models.py
    ├── test_batch_store.py
    ├── test_main.py
    ├── test_models.py
    ├── test_reconcile.py
    └── test_utils.py

Installation

This module is intended to be vendored or installed directly from source.

Requirements:

  • Python 3.10+
  • boto3 / botocore
  • AWS credentials configured for Bedrock + S3

Quick Start

from bedrockhelper import BedrockHelper

helper = BedrockHelper(
	region_name="ca-central-1",
	rag_model_id="global.anthropic.claude-sonnet-5",
	embedding_model_id="amazon.titan-embed-text-v2:0",
)

RAG Usage

Non-streaming

resp = helper.generate_with_rag(
    system_prompt="You are a helpful assistant.",
    context=["Doc 1", "Doc 2"],
    question="Summarize this",
)

print(resp.text)

Streaming

resp = helper.generate_with_rag(
    system_prompt="You are concise.",
    context="Some context",
    question="Stream this",
    stream=True,
)

for chunk in resp.stream:
    print(chunk, end="")

Sampling parameters

temperature has three meaningful states:

You pass Behaviour
nothing 0.1 is applied on models that accept it — low-variance output suited to RAG
a float your value is used
None nothing is sent; the model applies its own default (1.0 for Claude)
resp = helper.generate_with_rag(
    system_prompt="You are a helpful assistant.",
    context="Some context",
    question="Summarize this",
    temperature=0.3,
)

Newer Anthropic models reject sampling parameters entirely: temperature, topP, and topK were removed on Claude Opus 4.7, Opus 4.8, Opus 5, Fable 5, and Mythos 5, and Claude Sonnet 5 rejects any non-default value. Bedrock returns ValidationException: `temperature` is deprecated for this model.

On those models — including the default, global.anthropic.claude-sonnet-5 — the parameter is omitted for you and the request succeeds. A temperature you passed explicitly is dropped with a warning; the library's own default is dropped silently, since you never asked for it.

If a model rejects sampling parameters anyway — a family newer than this release, or Sonnet 4.5 / Haiku 4.5, which accept temperature alone but reject it alongside topP — the request is retried once without them and a warning is logged. New models therefore work without waiting on a BedrockHelper release.


Async Usage

resp = await helper.async_generate_with_rag(
    system_prompt="You are helpful",
    context="Context",
    question="Async answer?",
)

print(resp.text)

Streaming:

async for chunk in await helper.async_stream_generate_with_rag(
    system_prompt="You are helpful",
    context="Context",
    question="Async stream",
):
    print(chunk, end="")

Embeddings

Inline embeddings

records = {
    "a": "Hello world",
    "b": "Another document",
}

resp = helper.embed_texts(records)
print(resp.embeddings["a"])

Batch embeddings

job = helper.embed_texts(
    big_records,
    s3_bucket="my-bucket",
    s3_prefix="bedrock_batch",
    role_arn="arn:aws:iam::123456789012:role/BedrockBatchRole",
)

print(job.job_id)

Wait for completion:

info = helper.wait_for_batch_job(job.job_id)
print(info["status"])

Parse results:

embeddings = helper.parse_batch_embeddings(job.output_s3_uri)

Batch Job Reconciliation

The helper includes a small framework for tracking and reconciling batch jobs.

from bedrockhelper import InMemoryJobStore
from bedrockhelper.batch.reconcile import reconcile_batch_embedding_jobs

store = InMemoryJobStore()
store.add(job)


def process_embeddings(job, embeddings):
	print("Processed", len(embeddings))


reconcile_batch_embedding_jobs(
	helper=helper,
	store=store,
	process_embeddings=process_embeddings,
)

Implementing Your Own JobStore

To persist batch jobs across restarts or multiple workers, implement the JobStore interface.

Redis Example

Use Redis keys per job plus a sorted set for ordering.

Key ideas:

  • Store jobs as JSON
  • Use TTL for terminal jobs
  • Use a sorted set by created_at

This is ideal for horizontally scaled workers.

Postgres Example

Suggested schema:

CREATE TABLE bedrock_batch_jobs (
  job_id TEXT PRIMARY KEY,
  job_name TEXT NOT NULL,
  model_id TEXT NOT NULL,
  input_s3_uri TEXT NOT NULL,
  output_s3_uri TEXT NOT NULL,
  state TEXT NOT NULL,
  created_at TIMESTAMPTZ NOT NULL,
  last_checked_at TIMESTAMPTZ,
  attempts INTEGER NOT NULL DEFAULT 0,
  last_error TEXT,
  bedrock_status TEXT,
  processed_at TIMESTAMPTZ,
  embeddings_count INTEGER,
  debug JSONB NOT NULL DEFAULT '{}'::jsonb
);

This approach is boring, reliable, and production-friendly.


  • Submit batch jobs quickly and return job IDs
  • Reconcile in a background worker or cron
  • Make process_embeddings() idempotent
  • Prefer Postgres if you need observability

License

Internal / project-specific. Adapt as needed.

Metadata

Release files for bedrockhelper 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bedrockhelper 1.2.1
File Size Uploaded Provenance
bedrockhelper-1.2.1.tar.gz 24.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bedrockhelper 1.2.1
File Interpreter ABI Platform
bedrockhelper-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 54.1 kB

Release files / bedrockhelper-1.2.1.tar.gz

Download URL bedrockhelper-1.2.1.tar.gz
Size 24.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a645e9166521fd22e33010fe8a1e70ef015b5a8cbead2cc6f67ab0e7e352af0a
BLAKE2b-256 checksum
How to use checksums
621b4baa891b6734968833d65e3242fa8c277d67acae139003d04f8b7ac5e3e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / bedrockhelper-1.2.1-py3-none-any.whl

Download URL bedrockhelper-1.2.1-py3-none-any.whl
Size 29.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c046840754017255cfa2f91638f8de17a480366243e4ecb2176a64079362c71b
BLAKE2b-256 checksum
How to use checksums
d2ece12c532df9aeb76d29fec38a90b3478b8176f18cae704951d33ea07fb209
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Security for bedrockhelper 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bedrockhelper-1.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page