Skip to main content
PiyAPI provides the infrastructure for persistent intelligence across AI applications. The platform manages memory, context, and retrieval as distinct layers, allowing applications to store relevant information and recall it precisely when needed rather than relying on ephemeral session state. This document introduces the core building blocks of PiyAPI and describes how they compose into a working system for AI agents and applications.

Core Concepts

Persistent Memory

Long-term storage referenced via memory_id. Backed by the Unified 8-Operator Surface (store, retrieve, update, delete, merge, summarize, pin, verify).

Context

Assembled data passed via context object. Token-budget-aware context assembly for LLM system prompts via POST /api/v1/context/retrieve.

Users & Sessions

Scoped via user_id identifiers. Enterprise multi-tenancy enforced via strict namespace isolation (X-Namespace-Prefix header) and automated PHI/PII privacy redaction.

Retrieval

Query via client.search(). Hybrid search engine combining dense vector similarity (HNSW via pgvector) and BM25 trigram full-text search, fused using Reciprocal Rank Fusion (RRF_K=30).

Knowledge

Structured domain data accessible through knowledge.query(). PiyGraph Knowledge Graph tracking real-world validity (valid_at) separately from system recording time (system_at).

Architecture

Request flows from your application through the PiyAPI Gateway to the Memory Engine, Cognitive Engine, and Integrations, then down to the Vector Substrate (pgvector + Redis).
PiyAPI separates persistent memory from the application logic so your AI system can retrieve relevant context when it needs it.

System Architecture

Initialize the Client

Store and Retrieve Context

1

Create or initialize the client

Use the TypeScript SDK, Python SDK, or cURL to authenticate with your API key.
2

Send conversational information

Stream or batch events and messages into the system.
3

Store relevant memory

Persist facts, preferences, and context as tagged memory records.
4

Retrieve context when needed

Run a hybrid search query to pull back the most relevant memory.
5

Pass retrieved context to the model

Include the assembled context in the LLM prompt for generation.

Store a memory

example.js
example.js

Response

Use retrieval selectively so your application only sends relevant context to the model. Configure min_score (default 0.25) and alpha (vector vs BM25 blend, default 0.7) for precise control over retrieval quality.

How PiyAPI Works

What’s Next?

Explore the architecture

Understand how PiyGraph, bitemporal valid_at/system_at tracking, and Speculative Memory Branching are structured.

Store your first memory

Create and persist your first record using POST /api/v1/memories or the TypeScript SDK.

Build an AI agent

Wire up memory and context using our MCP Server (@piyapi/mcp-server, 30 tools, 3 resources, 3 prompts).

Explore the API

Browse the full REST reference and OpenAPI JSON spec at https://api.piyapi.cloud/docs/raw/openapi.json.