Skip to main content
<div align="center">

<img src="assets/logo.png" alt="NafsAI" width="120"/>

# NafsAI
### The Arabic-First Memory Layer for Local AI
### طبقة الذاكرة العربية للذكاء الاصطناعي المحلي

[![PyPI](https://img.shields.io/pypi/v/nafsai)](https://pypi.org/project/nafsai)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://python.org)
[![Arabic-First](https://img.shields.io/badge/Arabic--First-✓-green.svg)]()

**Arabic · English · No Cloud · No API · Your Device Only**

*Built in Saudi Arabia 🇸🇦*

</div>

---

## The Problem

Every AI chatbot you build forgets everything after each conversation.

كل chatbot تبنيه ينسى كل شيء بعد كل محادثة.

## The Solution

```python
from nafsai import Agent

agent = Agent()
answer = agent.chat("What do you remember about me?", your_llm)
# Remembers. Always. In Arabic and English.
# يتذكر. دائماً. بالعربية والإنجليزية.

Permanent memory. No cloud. Arabic-first. Works in English too.

ذاكرة دائمة. بدون سحابة. عربي أولاً. يعمل بالإنجليزية أيضاً.


Why NafsAI?

mem0 Zep Letta NafsAI
Arabic-First
No Cloud Required ⚠️ ⚠️ ⚠️
pip install only
No Docker
Local & Private ⚠️ ⚠️ ⚠️
Works Offline

Installation

pip install nafsai

That's it. No Docker. No server. No API key.

هذا كل شيء. بدون Docker. بدون خادم. بدون API key.


Quick Start

from nafsai import Agent

agent = Agent()

def my_llm(prompt: str) -> str:
    # your LLM here — Ollama, OpenAI, Gemini, anything
    return your_llm_function(prompt)

# First session
agent.chat("اسمي عبدالله وأنا مطور Python", my_llm)
agent.chat("My name is John and I work in Riyadh", my_llm)

# Close and reopen — memory persists
# أغلق وأعد التشغيل — الذاكرة تبقى

# New session
agent2 = Agent()
agent2.chat("هل تتذكرني؟", my_llm)
# → "نعم عبدالله، أنت مطور Python"

agent2.chat("Who am I?", my_llm)
# → "You are John, you work in Riyadh"

How It Works

Your App
    ↓
Agent   ← combines all components
    ↓
Router  ← classifies question  (coding / reasoning / general)
Memory  ← permanent storage    (SQLite + FTS5 + vectors)
Cache   ← smart TTL cache
Session ← current conversation context
    ↓
Your LLM ← Ollama / OpenAI / Gemini / anything

Three Memory Modes

NafsAI detects your environment and uses the best available mode:

Mode Engine Performance
full FTS5 + sqlite-vec Best
fts_only FTS5 only Good
numpy_only numpy cosine Always works

No configuration needed. It just works.


Components

Component Description الوصف
Memory Permanent local memory ذاكرة دائمة محلية
Router Smart question routing توجيه ذكي للأسئلة
Normalizer Arabic text normalization تطبيع النص العربي
Cache TTL-based smart cache كاش ذكي
Session Conversation context سياق المحادثة
Agent All-in-one interface واجهة موحدة

Works With Any LLM

# Ollama (local)
import ollama

def llm(prompt: str) -> str:
    return ollama.chat(
        model="llama3.2",
        messages=[{"role": "user", "content": prompt}],
    )["message"]["content"]

# OpenAI
from openai import OpenAI

client = OpenAI()

def llm(prompt: str) -> str:
    return client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": prompt}],
    ).choices[0].message.content

# Any function that takes str and returns str
agent.chat("your question", llm)

Tests & Quality

All tests pass across all memory modes:

Test File Coverage
test_agent.py Agent pipeline, cache hits, LLM errors, prompt building
test_memory.py Save/search, user facts, normalization, persistence, all 3 modes
test_cache.py TTL rules, route isolation, bad responses, Arabic normalization
test_router.py Keyword rules, semantic routing, Arabic & English questions
test_normalizer.py Hamza, Tashkeel, numbers, math symbols, mixed text
test_session.py Turn limits, context window, f-string format, truncation
pip install -e ".[dev]"
pytest
# ✓ All tests passed

---

## Privacy

✓ Everything stored locally — your device only ✓ No data leaves your machine ✓ No telemetry ✓ No internet required after installation ✓ GDPR-friendly by design


✓ كل شيء يُخزن محلياً على جهازك فقط ✓ لا بيانات تغادر جهازك ✓ لا تتبع ✓ لا إنترنت مطلوب بعد التثبيت


---

## Roadmap

- [x] SQLite + FTS5 + vector search
- [x] Arabic-English bilingual support
- [x] Smart fallback system

next version: 
- [ ] MCP server support

---

## Contributing

```bash
git clone https://github.com/NafsAI/NafsAI
cd NafsAI
pip install -e ".[dev]"
pytest

All contributions welcome — Arabic and English.

كل المساهمات مرحب بها — بالعربية والإنجليزية.


Built in Saudi Arabia 🇸🇦 — For the Arabic AI Ecosystem

PyPI · Documentation · Issues · Discussions

"The Arabic world deserves its own AI tools — built here, for here, by us."

"العالم العربي يستحق أدوات AI مبنية هنا، لنا، منّا."

```

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nafsai-0.1.1.tar.gz (158.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nafsai-0.1.1-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file nafsai-0.1.1.tar.gz.

File metadata

  • Download URL: nafsai-0.1.1.tar.gz
  • Upload date:
  • Size: 158.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for nafsai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ccc733f4acc29d416b156129bb59b17211efba3da60c8fa66c63c22d437c1960
MD5 ff2b474551b783ebecb5e77635eea237
BLAKE2b-256 688380d9542ad92251941a3d6c91957e7bde407f675d2f3614ba2f00f9e7aa56

See more details on using hashes here.

File details

Details for the file nafsai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nafsai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for nafsai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 22968ab0df46032176bc21711fca695341f22186532017647fbcc2bcd9ef77c6
MD5 6f6d5b0b5e6a6d353a96f8ac2479b27e
BLAKE2b-256 c8137139fcc108430d355a1798152682a91421e6f50e6504bc7e6eb249cb3be2

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.3

2 files

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page