Skip to main content
Glama
agent-search-core

agent-search-core

README.md
# agent-search-core

Local-first, evidence-backed search core for AI agents.

`agent-search-core` is not a SearXNG fork and not an Exa/Tavily client. The core is self-built or MIT-licensed. SearXNG may be added later as an optional adapter, never as the only backend.

[![Release](https://img.shields.io/github/v/release/Mizar-Silexeth/agent-search-core)](https://github.com/Mizar-Silexeth/agent-search-core/releases)
[![Tests](https://github.com/Mizar-Silexeth/agent-search-core/actions/workflows/test.yml/badge.svg)](https://github.com/Mizar-Silexeth/agent-search-core/actions)
[![Offline benchmark](https://img.shields.io/badge/benchmark-8%2F8%20offline-brightgreen)](docs/BENCHMARKS.md)
[![Website](https://img.shields.io/badge/website-live-brightgreen)](https://mizar-silexeth.github.io/agent-search-core/)
[![Listed in Awesome MCP Servers](https://sagargupta.online/awesome-mcp-servers/badge.svg)](https://github.com/Sagargupta16/awesome-mcp-servers)

| Search ledger | Grounded answer |
|---|---|
| ![Search ledger](docs/assets/demo-search.png) | ![Grounded answer](docs/assets/demo-answer.png) |

## What it provides

- one provider contract for eight vertical search lines;
- independent crawler, SQLite URL frontier, FTS5 index, and optional vector index;
- deterministic and optional local-LLM query planning;
- BM25 + cosine hybrid retrieval and optional local cross-encoder reranking;
- multi-round research loop with coverage and stop conditions;
- evidence-bound answer engine with verified `[n]` citations and claim support;
- conversation-aware follow-up query planning;
- optional browser rendering for JavaScript-heavy pages;
- TTL/LRU semantic-layer cache with singleflight and per-caller abort;
- claim-level citation support assessment;
- CLI, MCP stdio server, and DSH bundle adapter;
- isolated provider failures with structured diagnostics;
- canonical URL deduplication and evidence validation;
- provider-aware fusion instead of comparing incompatible raw scores;
- global result, character, item, diagnostic, and deadline budgets;
- verbatim citations with locators and offset validation;
- zero runtime dependencies.

## Providers

| Provider | Directory | Primary source |
|---|---|---|
| GitHub | `src/providers/github/` | GitHub REST API |
| npm | `src/providers/npm/` | npm Registry |
| Arxiv | `src/providers/arxiv/` | Arxiv Atom API |
| Official docs | `src/providers/docs/` | Operator-configured roots and sitemaps |
| Security advisories | `src/providers/security/` | CISA KEV + NVD |
| RSS news | `src/providers/news/` | Operator-configured RSS/Atom feeds |
| User sites | `src/providers/site/` | Allowlisted domains and sitemaps |
| Local knowledge | `src/providers/knowledge/` | Local Markdown/JSON/text, SQLite FTS5 or memory index |

## Quick start

```bash
npm install --ignore-scripts
npm run build
npm test
npm run typecheck
```

## Example

```ts
import { SearchOrchestrator } from './dist/src/index.js'
import { createGithubProvider } from './dist/src/providers/github/index.js'
import { createKnowledgeProvider } from './dist/src/providers/knowledge/index.js'

const orchestrator = new SearchOrchestrator([
  createGithubProvider({ token: process.env.GITHUB_TOKEN }),
  createKnowledgeProvider({ roots: ['./notes'] }),
])

const response = await orchestrator.search(
  { text: 'sqlite-vec', kinds: ['github', 'knowledge'], limit: 8 },
  { signal: new AbortController().signal, now: new Date(), requestId: 'demo', config: {} },
)

console.log(response.items)
```

## Evidence-bound answer

```ts
import { answerQuestion } from './dist/src/index.js'

const answer = await answerQuestion({
  query: 'What is sqlite-vec?',
  evidence: response.items,
})

console.log(answer.text)      // sentences with [n] citations
console.log(answer.citations) // verbatim, offset-validated quotes
console.log(answer.claims)    // support / refute / neutral / unknown
```

The default answerer is deterministic and extractive. An optional local OpenAI-compatible model can be enabled, but every generated citation is revalidated and unsupported sentences fall back to evidence.

## CLI

```bash
npx -y agent-search search "sqlite-vec" --provider github --limit 5
# Before npm publication, run directly from the tagged GitHub release:
npx -y github:Mizar-Silexeth/agent-search-core#v0.3.4 search "sqlite-vec" --provider github --limit 5
# Homebrew:
brew tap Mizar-Silexeth/agent-search-core
brew install agent-search-core
node dist/src/cli.js --help
node dist/src/cli.js search "sqlite-vec" --provider github --limit 5
node dist/src/cli.js crawl https://example.com --max-pages 20
node dist/src/cli.js eval --qrels eval/qrels.json
node dist/src/cli.js serve --port 8787
```

## Demo

```bash
node dist/src/demo-server.js --host 127.0.0.1 --port 4173
```

Open `http://127.0.0.1:4173` for the zero-dependency search/research/evidence UI. `GET /api/metrics` exposes bounded latency, citation, reliability, and answer-success metrics without retaining query text or URLs.

## MCP

The stdio MCP server exposes:

- `search`
- `fetch`
- `research`
- `crawl_status`

```bash
npx -y agent-search-core mcp
# or from a tagged GitHub release before npm publication:
npx -y github:Mizar-Silexeth/agent-search-core#v0.3.4 mcp
```

It uses newline-delimited JSON-RPC and has no runtime dependencies. A MCP Registry manifest is provided at [`server.json`](server.json).

## DSH

The standalone Host bundle lives in [`dsh-adapter/`](dsh-adapter/) and registers the core as a DSH web search provider. Install it as a local bundle after reviewing its manifest and patch.

## Evaluation

- `npm run eval`: deterministic offline provider smoke, 8/8.
- `node scripts/eval-v2.mjs --self-test`: metric self-check.
- `eval/qrels.json`: 138 labeled cases across eight providers.
- `eval/qrels/history-queries.json`: 150 real historical queries with sanitized provenance.
- Historical top results are candidates only; they are not promoted to relevance labels.
- Live mode reports `UNVER` for missing configuration or upstream failure instead of hiding it as an algorithm failure.

## Benchmark

```bash
node scripts/benchmark-v3.mjs --self-test
node scripts/benchmark-v3.mjs --track offline --mode both --limit 8
node scripts/benchmark-v3.mjs --track offline --mode both --ablation matrix
```

The public benchmark includes 138 frozen qrels, a 100/38 development/public-test split, schemas, manifests, base/enhanced comparison, A0–A9 ablations, latency, citation, claim, reliability, and stability metrics.

## Evidence rules

- `author` is only emitted when the upstream explicitly identifies an author.
- Invalid or partial dates are omitted rather than normalized into fabricated dates.
- `content` always has at least one valid citation.
- Offset citations must satisfy `content.slice(start, end) === quote`.
- Local knowledge paths are redacted by default.

## Security model

- Network providers use bounded timeouts and response sizes.
- `site` never lets query filters expand the operator allowlist.
- Private, loopback, link-local, multicast, and cloud-metadata addresses are blocked by default.
- Localhost HTTP is available only through an explicit test/operator option.
- `knowledge` roots come from trusted factory configuration, not request configuration.

## Examples

See [`examples/`](examples/) for basic search, grounded answers, conversation-aware research, and an MCP client configuration snippet.

## Documentation

- [Architecture and contracts](docs/01-架构与契约.md)
- [v0.2 architecture](docs/02-v2架构与契约.md)
- [v0.3 gap analysis](docs/research/v0.3-gap.md)
- [Answer engine](docs/research/answer-engine.md)
- [Public benchmark](benchmark/v0.3/README.md)
- [Benchmark snapshot](docs/BENCHMARKS.md)
- [Star strategy](docs/research/star-strategy.md)
- [Roadmap](docs/ROADMAP.md)
- [MCP Registry guide](docs/MCP_REGISTRY.md)
- [Changelog](CHANGELOG.md)
- [Prior-art and license decisions](docs/research/prior-art.md)
- [Project state](docs/state/STATE.md)
- [Provider research and verification](docs/research/providers/)
- [Qrels and evaluation](docs/research/qrels.md)

## Citation

See [`CITATION.cff`](CITATION.cff).

## License

MIT.