Metadata-Version: 2.4
Name: nitya
Version: 0.2.0
Summary: Nitya (नित्य): real-time web knowledge for your local open-source LLMs
Author-email: "Shashank Taxak, PhD (Aitele Research LLP)" <aiteleresearch@gmail.com>
Project-URL: Homepage, https://github.com/aiteleresearch/nitya
Project-URL: Issues, https://github.com/aiteleresearch/nitya/issues
Keywords: llm,local-llm,ollama,rag,web-search,mcp,openai-compatible
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Environment :: Console
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.27
Requires-Dist: trafilatura>=2.0
Requires-Dist: ddgs>=9.0
Requires-Dist: fastapi>=0.110
Requires-Dist: uvicorn>=0.29
Requires-Dist: mcp>=2.0
Requires-Dist: python-dateutil>=2.8
Requires-Dist: cryptography>=42
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"

# Nitya (नित्य)

**Real-time web knowledge for local open-source LLMs.**

A local model's knowledge stops at its training cutoff. Cloud assistants like Claude and Gemini stay current by searching the web while they answer, not by retraining. Nitya gives any local model that same ability as an add-on: you keep your own model (Llama, Qwen, Mistral, DeepSeek, Gemma, ...), and Nitya supplies the current date and fresh, dated, cited evidence from the web.

*Nitya* means "ever-present" and "daily": knowledge that is always current.

## How it works

```
question ──► Router ──► Search (web + news) ──► Read pages ──► Rank passages ──► Evidence pack ──► your model
             needs fresh    ddgs / SearXNG /     robots.txt,     BM25 + coverage    dated, numbered,
             facts?         Brave API            extraction      + trust + recency  ~1,250 tokens
```

Nitya plugs into your setup in two ways:

| Mode | Best for | How |
|---|---|---|
| **Proxy** (`nitya serve`) | Any model, even 1–3B ones | An OpenAI-compatible endpoint (and an Ollama-compatible one) in front of your model server. Nitya decides when to search, adds the evidence, and appends sources to the answer. The model only has to read. |
| **MCP tools** (`nitya mcp`) | Larger models that call tools well | Tools named `web_search`, `read_url` and `current_datetime`; the model decides what to look up. |

Small models are poor at choosing when to search and at reading whole pages, so the proxy does that work for them. Large models get the same evidence and can also run their own searches through MCP.

## Advanced search

Nitya picks a search mode for each request, so a model of any size gets the right kind of search:

| Mode | When | What Nitya does |
|---|---|---|
| **Answer** | "Who won IPL 2025?" | One search, best pages read, a short dated evidence pack. |
| **Find** | "Official site of ISRO", "download Ollama", "PDF of the RBI policy statement" | Several planned searches, results fused, **every link checked**: live or dead, final URL after redirects, last-updated date, official source or not. Dead links are dropped. |
| **Research** | "Compare X vs Y", "detailed overview of …" | Up to 4 planned searches, about 10 pages read, links to primary sources followed, and evidence chosen so **every part** of the question is covered. |

On top of these modes:

- **Search operators** work in any request: `site:`, `-site:`, `filetype:`, `after:YYYY-MM-DD`, `before:YYYY-MM-DD`. Nitya also enforces them on the results, because search engines sometimes ignore them.
- **Date limits**: `--since 24h | 7d | 2w | 3m | 1y | 2026-11-01`.
- **URL guard**: small models often invent plausible-looking URLs. Any link in an answer that Nitya did not check is marked "(unverified link)". The proxy response also lists it in `nitya.unverified_links`.
- **Optional planner model**: set `NITYA_PLANNER_MODEL` to a capable model, and it suggests extra queries for deep research. Without it, Nitya plans with fast rules, so even 1B models get multi-query search.

```powershell
nitya search "official website of ISRO"
nitya search "monetary policy statement site:rbi.org.in filetype:pdf" --since 3m
nitya search "Compare the 2025 Wimbledon and US Open men's champions"
nitya search "AI model releases" --since 7d --depth deep --json
```

The same search is available over HTTP at `POST http://127.0.0.1:11480/v1/search` (while Nitya runs):

```json
{"query": "budget speech", "intent": "find", "site": "indiabudget.gov.in", "filetype": "pdf", "since": "1y"}
```

The JSON response contains the plan (queries run), the checked pages, the evidence passages, the sources and timings. Over MCP, the same modes are the `web_search`, `find_pages` and `deep_research` tools.

Deep research runs several searches per request. The default `ddgs` provider is rate-limited by search engines, so for heavy use switch to SearXNG or the Brave API.

## Plans

| | Free | Pro | Max |
|---|---|---|---|
| Web search | Free metasearch (or your own SearXNG or Brave key), run on your computer | A commercial search index through the Nitya search gateway | The same, with a larger allowance |
| Searches a month | As the free engines allow | 1,500 | 4,000 |
| Computers | Any | 2 | 3 |
| Private dashboard | Included | Included | Included |
| API keys for your own apps | | Included | Included |
| Features | Everything | Everything | Everything |
| If the gateway refuses | n/a | Falls back to free search, with a notice | The same |

Pro and Max are opening to early customers: write to hello@aiteleresearch.com. With a key:

```sh
nitya plan --key nk_live_...   # activates this computer and shows the plan
nitya plan                     # plan, searches used this month, computers
nitya devices                  # the computers on the subscription
nitya devices --remove ID      # free one, to activate another
nitya plan --free               # back to the Free plan on this computer
```

With Pro or Max, the apps you build on your local models can each get a Nitya API key:

```sh
nitya keys create research-bot   # shown once; use it as the API key of any OpenAI or Ollama client
nitya keys                       # list them; nitya keys revoke NAME
```

Each app's requests show under its name in the dashboard. Set `require_api_key = true` to refuse requests without a key, for apps
on other devices or in containers. The keys work only with Nitya on your computers, in front of your local models.

A subscription works only on the computers activated for it. Each computer proves itself with its own device key, made inside its TPM security chip where there is one (`nitya/device.py`), so a copied license key is useless elsewhere. Pro and Max send only search queries to the gateway, never your conversations. The gateway's interface is in [docs/GATEWAY_API.md](docs/GATEWAY_API.md).

## Install

Nitya runs beside the model server you already use. Nothing about your models changes.

**Windows** (PowerShell):

```powershell
irm https://<your-site>/nitya/install.ps1 | iex
```

**macOS and Linux** (Terminal):

```sh
curl -LsSf https://<your-site>/nitya/install.sh | sh
```

The installer:

1. installs [uv](https://docs.astral.sh/uv/) if it is missing (uv brings its own Python, so Python does not need to be installed);
2. installs Nitya as a command-line tool in its own environment;
3. runs `nitya setup`.

`nitya setup` then:

- finds the model servers running on the computer;
- picks a default model that fits in its memory;
- chooses a search provider and a free port;
- checks that everything works;
- offers to start Nitya at login;
- shows how to connect your apps.

Run the same install command again to upgrade.

Other ways to install:

- `uv tool install "nitya @ https://<your-site>/nitya/nitya-<version>-py3-none-any.whl"`
- `pipx install https://<your-site>/nitya/nitya-<version>-py3-none-any.whl`
- from PyPI, once it is published there: `uv tool install nitya`

Then run `nitya setup`.

### Works with your model server

`nitya setup` finds these automatically:

| Model server | Usual address | Nitya talks to it through |
|---|---|---|
| Ollama | `localhost:11434` | OpenAI API and Ollama's own API |
| LM Studio | `localhost:1234` | OpenAI API |
| llama.cpp server, LocalAI | `localhost:8080` | OpenAI API |
| vLLM | `localhost:8000` | OpenAI API |
| Jan | `localhost:1337` | OpenAI API |
| KoboldCpp | `localhost:5001` | OpenAI API |
| text-generation-webui | `localhost:5000` | OpenAI API |
| Anything else, local or remote | any URL | OpenAI API: `nitya setup --upstream http://host:port/v1` |

### Connect your apps

Point your chat app at Nitya instead of at the model server. `nitya connect` prints these addresses for your setup.

| Your app speaks | Use this address | Examples |
|---|---|---|
| The OpenAI API | `http://127.0.0.1:11480/v1` (any API key) | Open WebUI (OpenAI connection), AnythingLLM ("Generic OpenAI"), LibreChat, Continue, Msty, the OpenAI SDKs |
| Ollama's API | `http://127.0.0.1:11480` | Apps that ask for an "Ollama URL" (Open WebUI's Ollama connection, Enchanted, Page Assist, and others). Needs Ollama as the model server. |
| MCP tools | run `nitya connect --mcp-json` and paste the result | LM Studio, Claude Desktop, Jan, agent frameworks |

Notes:

- **Open WebUI in Docker** cannot reach `127.0.0.1` on your computer. Start Nitya with `nitya serve --host 0.0.0.0` and use `http://host.docker.internal:11480/v1`. This makes Nitya reachable from your local network, so only do it on networks you trust.
- **Browser extensions** must be allowed explicitly: Nitya refuses requests from websites and extensions unless you list them, for example `NITYA_ALLOWED_ORIGINS=chrome-extension://*`. Otherwise any web page you visit could use it.
- **Response details:** responses carry `X-Nitya-Searched` and `X-Nitya-Sources` headers. Non-streaming OpenAI responses also include a `nitya` field with the queries run, sources and timings.
- **What passes through untouched:** Ollama's other routes (`/api/tags`, `/api/pull`, embeddings and so on) and code-completion requests (`/api/generate` with a `suffix`).

### Run it in the background

```sh
nitya service install     # start Nitya at login (no admin rights needed)
nitya service status
nitya service stop | start
nitya service uninstall
nitya doctor              # check the model server, search, web access and the service
```

How each system starts it at login:

| System | Mechanism | Window |
|---|---|---|
| Windows | a shortcut in your Startup folder | runs with `pythonw`, so no console window |
| macOS | a LaunchAgent | |
| Linux | a systemd user service | |

Logs are in `~/.nitya/logs/nitya.log`.

### Your dashboard

Three ways in, whichever is nearest:
- the **Nitya Dashboard** shortcut, which setup adds to the Start menu and desktop (Windows), Applications (macOS) or the app launcher (Linux);
- `nitya dashboard`, which also starts Nitya if it isn't running;
- **http://127.0.0.1:11480** in any browser.

`nitya` on its own shows whether Nitya is running and where the dashboard is. The dashboard shows:
- **your models**: each model that talks to Nitya, whether it is answering, and how long searches and answers take;
- **activity**: every request, with the app, whether Nitya searched, the search words, the sources found and the result;
- what Nitya has done for you: questions, searches by kind, pages read, links checked, invented links caught, and the sites your answers came from;
- your plan and its computers;
- the privacy and update switches.

Its history stays in `~/.nitya/usage.sqlite` on your computer, for 90 days. It never holds your conversations or the answers;
`search_history = false` leaves out the search words too. Clear it or turn it off from the page (`local_stats = false`). Your Nitya ID is the start of this computer's device-key fingerprint: no account, email or password.

### Updates

The background service checks for a new version every six hours. It installs one only if it is:
- signed with Aitele's release key;
- newer than yours;
- intact (its checksum matches).

It waits until no app is using Nitya, and puts the old version back if the new one does not start. Everything in `~/.nitya` is kept: settings, history, counters and the Pro session. `nitya update` installs now; `nitya update --check` only looks; `auto_update = false` turns it off. The log is `~/.nitya/logs/update.log`.

## The website

The Nitya website is in [`website/`](website/README.md): a 3D home page, live counters with a statistics overlay, and the legal pages. It is built with `python website/build.py`.

## Public statistics

The website shows how many people have visited it, how many have installed Nitya successfully, and how many searches Nitya has made, by plan:
- **The count:** after a successful `nitya setup`, Nitya sends a random install ID once, and on the free plan it reports search counts every 10 minutes at most. Only numbers are sent, never questions or search words.
- **Turning it off:** answer "no" in setup, use `nitya setup --no-count`, set `count_me = false` in the config, or set `DO_NOT_TRACK=1`.

## Releases and the server

Everything public lives at **https://nitya.aiteleresearch.com**: the website, the installers under `/download`, and the search gateway under `/v1`. The server, its HTTPS, daily off-site backups, and how to move it to another VM or cloud without losing any subscription, are in [deploy/README.md](deploy/README.md).

Build a signed release kit on your own computer (the signing key stays there, in `~/.nitya-release/`; make it once with `--new-signing-key`):

```powershell
.\.venv\Scripts\python.exe tools\make_release.py --base-url https://nitya.aiteleresearch.com/download --out dist\release
```

This writes `dist/website/`:

| File | Purpose |
|---|---|
| `nitya-<version>-py3-none-any.whl` | the package |
| `install.ps1`, `install.sh` | installers that point at that wheel on your site |
| `index.html` | a plain install page to restyle |
| `latest.json`, `latest.json.sig` | the current version, wheel address and checksum, and its Ed25519 signature |
| `SHA256SUMS` | checksums |

Publish it with `sudo ./deploy/install.sh --release DIR` on the server. For each new version, bump `__version__` in `nitya/__init__.py`, rebuild and publish: installed copies update themselves within six hours.

## Development

```powershell
py -3.12 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[dev]"
.\.venv\Scripts\python.exe -m pytest
.\.venv\Scripts\nitya.exe ask "Who won the 2025 Nobel Peace Prize?" --model qwen2.5:1.5b
.\.venv\Scripts\nitya.exe ask "Who won the 2025 Nobel Peace Prize?" --evidence-only
```

## Configuration

`nitya setup` writes `~/.nitya/config.toml`, which you can edit. `NITYA_*` environment variables override it, and command-line flags override both. Set `NITYA_HOME` to keep the config, cache and logs somewhere other than `~/.nitya`.

| Variable | Default | Meaning |
|---|---|---|
| `NITYA_UPSTREAM_URL` | `http://localhost:11434/v1` | Your model server (OpenAI-compatible) |
| `NITYA_UPSTREAM_API_KEY` | | Key for the model server, if it needs one |
| `NITYA_OLLAMA_URL` | derived | Ollama's own API, for apps that speak it (set automatically when the model server is Ollama) |
| `NITYA_PORT` | `11480` | Nitya's port (`nitya setup` picks a free one) |
| `NITYA_HOST` | `127.0.0.1` | Use `0.0.0.0` only to reach Nitya from Docker or other machines |
| `NITYA_ALLOWED_ORIGINS` | | Extra browser origins allowed to call Nitya, comma-separated (e.g. `chrome-extension://*`) |
| `NITYA_SEARCH_PROVIDER` | `ddgs` | `ddgs` (no key, for development), `searxng`, or `brave` (commercial index) |
| `NITYA_SEARXNG_URL` | `http://localhost:8080` | Your SearXNG instance (enable the JSON format) |
| `NITYA_BRAVE_API_KEY` | | Brave Search API key |
| `NITYA_MODE` | `auto` | `auto` (search when needed), `always`, or `never` |
| `NITYA_CONTACT` | | Email or project URL added to the User-Agent. **Set this:** Wikipedia and some other sites refuse requests without contact details. |
| `NITYA_MAX_PAGES` | `5` | Pages read in full per question |
| `NITYA_EVIDENCE_CHARS` | `5000` | Size of the evidence pack (~1,250 tokens) |
| `NITYA_RESPECT_ROBOTS` | `true` | Obey robots.txt (keep this on) |
| `NITYA_APPEND_SOURCES` | `true` | Add a Sources list to proxied answers |
| `NITYA_CACHE_PATH` | `~/.nitya/cache.sqlite` | Store of pages already read |
| `NITYA_CACHE_TTL_MINUTES` | `30` | How long a cached page counts as fresh |
| `NITYA_MODEL` | chosen by setup | Default model for `nitya ask` and `nitya eval` |
| `NITYA_DEEP_MAX_QUERIES` | `4` | Searches planned for one deep-research request |
| `NITYA_DEEP_MAX_PAGES` | `10` | Pages read in deep research |
| `NITYA_DEEP_EVIDENCE_CHARS` | `8000` | Evidence size in deep research (~2,000 tokens) |
| `NITYA_FOLLOW_LINKS` | `true` | Deep research also reads the most relevant pages linked from results |
| `NITYA_VERIFY_LINKS` | `true` | Check every link in find mode |
| `NITYA_GUARD_URLS` | `true` | Mark links in answers that Nitya did not check |
| `NITYA_PLANNER_MODEL` | | Optional model that suggests extra search queries |

## The scorecard

The scorecard asks each question twice, once to the model alone and once through Nitya, and grades the answers against accepted answers:

```powershell
nitya eval --model qwen2.5:1.5b --model qwen2.5:3b
```

The built-in question sets (in `nitya/questions/`) are:

- `post_cutoff_2025.jsonl`: facts from 2025 that most open models were trained too early to know.
- `timeless_controls.jsonl`: questions that need no search. Nitya should skip searching and must not make these answers worse.
- `find_pages.jsonl`: requests for official sites, downloads and papers. The answer must contain the right URL.
- `research_multi_part.jsonl`: comparisons and multi-part questions. Every part must be answered.

Every link a model gives is checked afterwards, so the report also shows how many links in each mode actually work.

Reports are written to `~/.nitya/results/<time>-<model>/report.md`. Add your own `.jsonl` files with fields `id`, `question` and `category`, plus either `answers` (any one counts as correct) or `all_of` (one list of aliases per required part).

Grading is a whole-word match against accepted answers, ignoring case and accents. It is quick and repeatable but strict about wording, so read the report's answers when a score looks off.

## Results so far

Measured on 3 December 2026 on a laptop with 7.4 GB of RAM and no GPU (Ryzen 5 5500U), using small Qwen models through Ollama and the free `ddgs` search provider.

| Question set | qwen2.5:1.5b alone | 1.5b + Nitya | qwen2.5:3b alone | 3b + Nitya |
|---|---|---|---|---|
| Post-cutoff facts (19) | 1 | **18** | 1 | **19** |
| Timeless controls (6) | 6 | 6 (no search) | 6 | 6 (no search) |
| Find the right link (6) | 3 | **6** | - | - |
| Multi-part research (4) | 0 | **4** (3 before the part checklist) | - | - |

What the runs taught us, and what changed as a result:

- **Small models copy formats.** The first prompt made the 1.5B model reply just "[1]". Asking the question before and after the evidence, and asking for a full-sentence answer, fixed it.
- **Nearby facts distract small models.** "Federer has won Wimbledon 8 times" next to "Sinner won Wimbledon 2025" produced "Federer". Trimming each passage to the sentences about the question fixed it.
- **Headlines hurt questions about past years.** A question about 2025 asked in December 2026 picked up 2026 news, such as the 2026 Ballon d'Or winner. Nitya now skips news search for finished years.
- **Long research packs confuse small models.** Comparing two football finals, the 1.5B model blended them into an invented "Inter Milan won in Budapest". Two fixes: a checklist of the parts to answer, and a shorter research pack for models of 4B or less (the size is read from the model's name).
- **Models invent links.** Without Nitya, the 1.5B model gave `arxiv.org/abs/1706.03769` for "Attention Is All You Need". That link works but points to a different paper. With Nitya the model copies the verified link.
- **The answer time is the model's, not Nitya's.** Searching takes about 5–15 seconds (25–35 for deep research), and a CPU-only laptop needs 10–50 seconds to generate an answer. A GPU cuts the second number sharply.

## Roadmap

1. **Query-time search** (this version): router, search, extraction, ranking, evidence pack, proxy, MCP and scorecard, plus advanced search (find mode with checked links, deep research, search operators, URL guard).
2. **Dūta, the push streams**: Wikipedia live edits, RSS/WebSub, GitHub releases, Hacker News and others feeding a local index continuously, so common questions are answered in under a second.
3. **Smṛti, the date-aware store**: story clusters (one wire story reprinted 300 times counts once) and a fact timeline that records when each fact became true or stopped being true.
4. **Pramāṇa, verification**: corroboration by independent sources, learned source trust, conflict and correction tracking.
5. **Live scorecard**: daily questions built from the previous day's news, compared head-to-head with Claude and Gemini with web search.

## Responsible crawling

Nitya fetches pages only when a question needs them, on the user's behalf, much as a browser does. It obeys robots.txt (RFC 9309) and identifies itself honestly in the User-Agent. It skips social-media and video sites and caps page size. Respect each site's terms and paywalls. If you change the search provider, check its terms on storing and caching results before building on them.
