Skip to main content

piyapi-llamaindex

A LlamaIndex memory block backed by PiyAPI. Add it to LlamaIndex's Memory: before each turn it recalls what PiyAPI knows that is relevant to the latest user message, and the turns Memory flushes out of its short-term queue are stored in PiyAPI.

PiyAPI by Negentro is the memory layer for AI agents: 84.1% on BEAM-1M, 93.6% on LongMemEval-S and 97% fewer tokens than the full history, with every answer published. Start for free · Docs · Benchmarks

pip install piyapi-llamaindex

Quick start

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.core.memory import Memory
from piyapi_llamaindex import PiyAPIMemoryBlock

block = PiyAPIMemoryBlock(namespace="user-123")  # api_key defaults to PIYAPI_API_KEY
memory = Memory.from_defaults(session_id="user-123", token_limit=30000, memory_blocks=[block])

agent = FunctionAgent(tools=[...], llm=llm)
response = await agent.run("Which seat should I book?", memory=memory)

Memory puts the block's text into the system message (or the latest user message, with insert_method=InsertMethod.USER) as <memory><PiyAPIMemory>...</PiyAPIMemory></memory>.

Options: PiyAPIMemoryBlock(name="PiyAPIMemory", namespace="default", api_key=None, base_url=None, timeout=4.0, max_context_tokens=None, fail_open=True, low_confidence_note=LOW_CONFIDENCE_NOTE, on_lookup=None, transport=None, http_client=None, priority=0, accept_short_term_memory=True). base_url defaults to PIYAPI_BASE_URL, else https://api.piyapi.cloud; trailing slashes and a trailing /api/v1 are removed. Every request sends Authorization: Bearer <key>, Content-Type: application/json and X-PiyAPI-Client: piyapi-llamaindex/0.1.0. The API key is left out of repr and model_dump.

What it sends

Block method PiyAPI request
aget(messages) POST /api/v1/ask {query, namespace, returnContextOnly: true} (plus maxContextTokens when set); returns the response's context, or "" when abstained is true; a weak match adds one line (below)
aput(messages) POST /api/v1/conversations/ingest {messages: [{role, content}], namespace}; PiyAPI stores overlapping windows of the conversation as memories
  • The query is the text of the latest user message (its text blocks joined). With no user text, nothing is sent and the block returns "". A query longer than PiyAPI's 2,000-character limit keeps its last 2,000 characters.
  • Roles: user -> user; assistant, chatbot, model -> assistant; system, developer -> system; tool, function -> tool. Messages without text (empty, whitespace, only tool-call or image blocks) are skipped.
  • A message over 50,000 characters is sent as several messages with the same role; more than 500 messages are sent in parts of 500 (same conversation_id, message_offset set). When PiyAPI answers 207 with truncated: true, the block resumes from next_message_index, as the API asks.
  • BaseMemoryBlock has only async methods, so the block has no sync wrappers; Memory.get() / Memory.put() run the async ones for you.

When the memories may not answer

PiyAPI says whether the memories it found match the question (servers from 2026-11-29): abstain, abstain_reason and relevance on the /ask response. When abstain_reason is "LOW_CONFIDENCE_MATCH" (the best matches are weak, by /search/hybrid's rule), the block keeps the context and puts one line after it, LOW_CONFIDENCE_NOTE:

These memories may not answer this question (none matched it closely).

The signal is advisory: it also flags some answerable questions (1 of 130 held out), so the context is never dropped on it; only abstained (no memory came back) gives "". low_confidence_note="..." changes the line, and None or "" leaves it out. To see the signal yourself, pass on_lookup: it is called (or awaited, for a coroutine function) with each lookup's query, namespace, context and sources, plus abstain, abstain_reason and relevance when the server sent them. An error it raises is logged, never raised.

def log_lookup(lookup):
    if lookup.get("abstain_reason") == "LOW_CONFIDENCE_MATCH":
        logger.info("weak recall for %r: %s", lookup["query"], lookup["relevance"])

block = PiyAPIMemoryBlock(namespace="user-123", on_lookup=log_lookup)

Failing open

Memory must not take the agent down. A timeout (default 4 seconds, for the whole request), a network error, an error status or a non-JSON answer is logged as a warning on the piyapi_llamaindex logger; aget then returns "" and aput stores nothing (a multi-part ingest stops at the first failure). Pass fail_open=False to raise PiyAPIError (with status_code and the server's code) instead. Requests are not retried.

A new httpx.AsyncClient is opened per call (safe across the event loops Memory's sync methods create). To reuse connections, pass your own http_client=httpx.AsyncClient(...); the block never closes it.

Limits

  • PiyAPI namespace names: letters, digits, . _ : -, starting with a letter or digit, at most 100 characters.
  • /ask queries: at most 2,000 characters; maxContextTokens 500-400,000.
  • Ingest: 1-50,000 characters per message, at most 500 messages and 50 stored windows per request (handled as above). Each window must fit your plan's per-memory size; PiyAPI splits long windows itself.

Tests

cd packages/llamaindex-memory
python -m pytest -q

The tests use httpx.MockTransport (no network, no model calls) and include runs inside LlamaIndex's own Memory (flush into ingest, context injected into the system message, sync wrappers, PiyAPI down).

Metadata

Release files for piyapi-llamaindex 0.1.0

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

Source distribution (sdist)

Source distribution for piyapi-llamaindex 0.1.0
File Size Uploaded Provenance Actions
piyapi_llamaindex-0.1.0.tar.gz 15.1 kB Without provenance Details for piyapi_llamaindex-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for piyapi-llamaindex 0.1.0
File Interpreter ABI Platform Actions
piyapi_llamaindex-0.1.0-py3-none-any.whl Python 3 none any Details for piyapi_llamaindex-0.1.0-py3-none-any.whl

Total release size: 26.6 kB

Release files / piyapi_llamaindex-0.1.0.tar.gz

Download URL piyapi_llamaindex-0.1.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c07aec299a02d85686070131f402681578f4846207defdf2059914d6f420dc87
BLAKE2b-256 checksum
How to use checksums
3030b5d71f6de744526d50833a551981ca68a854c75ccd08cc48a75387f8d6f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / piyapi_llamaindex-0.1.0-py3-none-any.whl

Download URL piyapi_llamaindex-0.1.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ccd732e26fd85dd0fcb3000068b0191468ee825935b9d759f6f0d78711d1472
BLAKE2b-256 checksum
How to use checksums
52f08d544dc1a0ac6f98b63972877ce8fc86d404470e9d920b3bf20b7086ea08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Security for piyapi-llamaindex 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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