NexaMem
NexaMem helps Python chatbots and AI agents remember across conversations without requiring you to build a custom persistence layer. Store conversation history, preferences, summaries, and task notes through one API, with explicit retention and control over what your application remembers.
Start locally with in-memory storage, JSON files, or SQLite, then move to Azure Redis, including Azure Managed Redis, without rewriting your memory API calls. Optional integrations connect that persistence to LangChain, AutoGen, Semantic Kernel, and Microsoft Agent Framework. Renewable Entra ID authentication and optional OpenTelemetry instrumentation reduce the identity and observability plumbing your application needs to maintain.
Why NexaMem?
- One API across storage backends. Store, retrieve, list, search, and delete text records without writing a separate persistence layer for each backend.
- Context organized around your application. Attach metadata and group records by conversation, user, or task using caller-defined scopes. Scopes organize data; they are not access controls.
- Sync and async interfaces. File and SQLite async operations run in worker threads, keeping blocking data I/O off the event loop.
- Explicit retention and framework integrations. Set per-record TTLs and use optional LangChain, AutoGen, Semantic Kernel, and Microsoft Agent Framework integrations.
- Optional observability. Correlate memory operations with OpenTelemetry traces and metrics, including application-configured Azure Monitor/Application Insights export.
Typical Uses
- Chatbots: persist conversation messages and retrieve history when assembling the next prompt.
- Personal assistants: save explicitly captured preferences and application-generated summaries for later conversations.
- Agent workflows: retain task notes and intermediate text results so subsequent steps can retrieve them by ID or search within a scope.
Your application decides what to remember and what to include in a model's context. NexaMem supplies storage and text-based search, not automatic memory extraction, embeddings, or semantic retrieval.
Install
This checkout requires Python 3.11 or newer. CI targets Python 3.11, 3.12, and 3.13 on Linux, Windows, and macOS. Published older versions may have different requirements.
The examples below target the proposed 1.0 release in this checkout, not an older PyPI package. Clone or download this repository, select the reviewed release-preparation commit, create and activate a virtual environment using the platform-specific steps in installation, then run from the repository root:
python -m pip install -e .
python -m pip check
To install the currently published release instead, use python -m pip install nexamem and documentation matching its installed version. After 1.0.0 is published and verified, install that release with python -m pip install "nexamem==1.0.0"; that command is not available before publication. Review migration notes before upgrading an existing store.
Contributors can install python -m pip install -e ".[dev]" instead to add test and development tools. No uv installation or commands are required. The local quick starts below need no Azure account, credentials, YAML configuration, or telemetry setup.
Quick Start
from nexamem import AIMemory, AIMemoryConfig, StorageConfig
with AIMemory(
AIMemoryConfig(default_scope="conversation-42", storage=StorageConfig.memory())
) as memory:
memory_id = memory.store("The customer prefers email.", metadata={"source": "chat"})
record = memory.retrieve(memory_id)
assert record is not None
assert record["content"] == "The customer prefers email."
assert memory.search("email") == [memory_id]
assert memory.delete(memory_id)
Successful assertions produce no output. In-memory records do not survive process exit. Use StorageConfig.file("./memory-data") or StorageConfig.sqlite("./memory.db") for local persistence. Reads return a record containing id, content, metadata, scope, and timestamps, or None when absent.
Async
import asyncio
from nexamem import AsyncAIMemory, AIMemoryConfig, StorageConfig
async def main():
async with AsyncAIMemory(
AIMemoryConfig(default_scope="conversation-42", storage=StorageConfig.memory())
) as memory:
memory_id = await memory.store("Remember this preference.")
record = await memory.retrieve(memory_id)
assert record is not None
assert record["content"] == "Remember this preference."
assert await memory.delete(memory_id)
asyncio.run(main())
Use with AIMemory(...) or async with AsyncAIMemory(...) to release facade-owned resources. File and SQLite async data operations offload synchronous I/O to worker threads; constructors still initialize synchronously. Cancelling an operation waits for its worker before releasing the per-adapter lock and is not rollback. Storage supplied through a DI container remains caller-owned.
In a notebook with an event loop already running, call await main() instead of asyncio.run(main()). See local persistence verification for a SQLite example that reopens stored data.
Retention
from nexamem import AIMemory, AIMemoryConfig, StorageConfig
with AIMemory(AIMemoryConfig(storage=StorageConfig.memory(), default_ttl_sec=3600)) as memory:
memory_id = memory.store("Short-lived note", ttl_sec=60)
assert memory.retrieve(memory_id) is not None
memory.purge_expired()
The new facades enforce logical expiry for generic records and channel writes across all backends. Expired records are hidden from retrieve, list, search, and compatibility read. Expiry is stored in reserved metadata _nexamem_expires_at. Reads attempt deletion; purge_expired() explicitly removes expired records, across all scopes when no scope is supplied. This is not immediate physical erasure, background cleanup, audit/backup deletion, or a transactional guarantee against concurrent writers. Raw storage and retained legacy APIs do not enforce this facade-level rule. See retention details.
Backends
| Backend | Configuration | Notes |
|---|---|---|
| Memory | StorageConfig.memory() |
Process-local, not persistent |
| File | StorageConfig.file("./memory-data") |
JSON records and indexes; individual record writes are atomic, not multi-file transactions |
| SQLite | StorageConfig.sqlite("./memory.db") |
Persistent local database; no external service required |
| Azure Redis | StorageConfig.azure_redis(AzureRedisConfig(...)) |
Requires a separately configured service; see Azure setup and limitations |
Redis, redis-entraid, fakeredis, PyYAML, and Azure identity/Key Vault clients remain runtime dependencies for compatibility. There is no azure extra. Optional framework extras are langchain, autogen, semantic-kernel, and agent-framework; observability extras are telemetry and appinsights. Development extras are dev, docs, perf, and all.
Framework Integrations
Optional integrations prepared for 1.0; these badges indicate adapter compatibility, not framework endorsement or availability in an older PyPI package. Supported SDK ranges and tested versions are recorded in the integration guide.
Install only the framework extra you use, for example python -m pip install -e ".[agent-framework]". Framework packages are not imported by the base package. The integrations provide LangChain typed chat history, AutoGen text memory, Semantic Kernel ChatHistory snapshot persistence, and an Agent Framework HistoryProvider.
See integration examples and compatibility limits, including Microsoft Foundry hosting. Foundry is a hosting/service integration, not a fifth framework adapter or a replacement for Foundry-managed conversation state.
Observability
Observability is optional. The telemetry extra installs the OpenTelemetry API; your application supplies its SDK, providers, sampling, exporters, and shutdown/flush lifecycle. Without the API, operations run normally. With the API but no configured providers, telemetry is a no-op. NexaMem never configures global providers or starts an exporter itself.
For generic OpenTelemetry support in this source checkout:
python -m pip install -e ".[telemetry]"
For Azure Monitor/Application Insights, the appinsights extra also installs the Azure Monitor OpenTelemetry distribution:
python -m pip install -e ".[appinsights]"
Set APPLICATIONINSIGHTS_CONNECTION_STRING in the application's environment. Configure Azure Monitor once at application startup, before using NexaMem; do not initialize a second pipeline if your host already provides one. For Azure-hosted production applications, prefer managed identity with the required Application Insights permissions:
from azure.identity import DefaultAzureCredential
from azure.monitor.opentelemetry import configure_azure_monitor
configure_azure_monitor(
credential=DefaultAzureCredential(),
logger_name="my_application",
enable_live_metrics=False,
)
from nexamem import AIMemory, AIMemoryConfig, StorageConfig
memory = AIMemory(AIMemoryConfig(storage=StorageConfig.memory()))
memory.store("The customer prefers email.")
See the Azure Monitor Python configuration reference and Microsoft Entra authentication requirements.
The public AIMemory and AsyncAIMemory data operations, including compatibility write()/read(), emit nexamem.<operation> spans under instrumentation scope nexamem, an operation counter (nexamem.operations), and a duration histogram in seconds (nexamem.operation.duration). Spans retain the caller's active context across sync calls and awaits; independently instrumented backend calls can become child spans. Counter and duration attributes contain only the operation name and success/error outcome. Exceptions and cancellations propagate unchanged; spans record only their exception class, not messages or stack traces. Missing records and unsuccessful boolean results are normal results, not exceptions.
NexaMem's instrumentation does not capture content, metadata, search queries, record IDs, scopes, user/session IDs, or credentials. Review your application's other instrumentations and logging separately: their data collection is outside this guarantee. No trace context is automatically stored with memories or passed between agents/processes. The retained legacy facades and standalone storage APIs are not instrumented by this integration; the legacy in-process metrics collector remains separate.
Channels and Guarantees
AIMemory and AsyncAIMemory retain write()/read() channel compatibility methods. Configure channels through YAML or register_channel(). Channel scopes include environment, agent, user, session, and channel; UTF-8 bytes are decoded on write.
Policy/content-processing helpers and the retained Redis-oriented legacy facade are separate APIs. Do not assume their behavior applies automatically to the new facade. See compatibility and migration and security limitations.
Development
python -m pip install -e ".[dev]"
python -m pytest tests/ -m "not integration" --cov=nexamem --cov-report=term-missing --cov-fail-under=90
python -m ruff check src/ tests/ build_and_test.py
python -m ruff format --check src/ tests/ build_and_test.py
python -m mypy src/
python build_and_test.py --dist-dir dist-release
The line-coverage gate covers the complete package, including retained legacy modules. Tests use local backends, fakeredis, and mocked Azure identity; passing unit tests is not live Azure certification. Strict mypy passes across the complete package and remains a blocking gate.
Documentation
- Installation and dependency policy
- Architecture and backend limitations
- Framework adapters and Foundry hosting
- Legacy API and data migration
- Channel YAML validation
- Async testing
- Contributor and release workflow
- Release status
- Security reporting
Licensed under the MIT License.
Metadata
Release files for nexamem 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nexamem-1.0.0.tar.gz | 87.4 kB | With provenance | Details for nexamem-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nexamem-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for nexamem-1.0.0-py3-none-any.whl |
Total release size: 157.2 kB
Release files / nexamem-1.0.0.tar.gz
| Download URL | nexamem-1.0.0.tar.gz |
|---|---|
| Size | 87.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24f2d67d497f239121f93f5dd0fec2c3da4dbd694bd867f45d1e8cde7c7b80b2
|
|
BLAKE2b-256 checksum How to use checksums |
4808295a37b2b4ffc71a87e1c19669d0fb217bc4d58380fa1b5c178d5dde5159
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 29, 2026.
Transparency logRelease files / nexamem-1.0.0-py3-none-any.whl
| Download URL | nexamem-1.0.0-py3-none-any.whl |
|---|---|
| Size | 69.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d2f60991d2cafbe2c193a2ad8283151d8b5d70f2295c0e6dea9ab71085af115
|
|
BLAKE2b-256 checksum How to use checksums |
06a045306820ea371bb9e31830c508a0f769ad0c371287750c4db014f1497688
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 29, 2026.
Transparency logSecurity for nexamem 1.0.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for nexamem-1.0.0.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 29, 2026.
Transparency logA 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.