<div align="center">
<img src="assets/logo.png" alt="NafsAI" width="120"/>
# NafsAI
### The Arabic-First Memory Layer for Local AI
### طبقة الذاكرة العربية للذكاء الاصطناعي المحلي
[](https://pypi.org/project/nafsai)
[](LICENSE)
[](https://python.org)
[]()
**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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nafsai-0.1.2.tar.gz.
File metadata
- Download URL: nafsai-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e674e272317ff9d3aa833e95a4c8f5e94fac79c8cad00b7ac5ccc92e92793c35
|
|
| MD5 |
0d12723ef73276f6a2913953268df5b3
|
|
| BLAKE2b-256 |
194f28bf92dfaf65efc0539aa304039703012e0fd22ad03e61900b50430725da
|
File details
Details for the file nafsai-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nafsai-0.1.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6933502c403c11e8722d22bd399ea154e43d7c69589070b07b9dee6c81241de
|
|
| MD5 |
493ad87c9fe65530e654f9c10f6ee6c5
|
|
| BLAKE2b-256 |
7d16900c6659c6d58b189c4bf8f07f1d10ce03c633c457e8628efbe6326b73c8
|