LastSearch
Research infrastructure for AI agents with Grounded Intelligence — real-time web search, evidence extraction, verification, and structured citations. Every claim is backed by a URL. Every answer has a confidence score.
Agent → LastSearch → Internet → Verified answers + sources
Website · Playground · API Docs · Alternatives · Discord
Package names: npm:
lastsearch· PyPI:lastsearch· LangChain:langchain-lastsearch— Previouslylastsearchandlastsearch. Old names still work and redirect automatically.
How It Works
search → fetch pages → neural rerank → extract claims → verify → cited answer (streamed)
Every answer goes through a multi-step verification pipeline. No hallucination. Every claim is backed by a real source.
Verification & Confidence Scoring
Confidence scores are evidence-based — not LLM self-assessed. After the LLM extracts claims and sources, a post-extraction verification engine checks every claim against the actual source page text:
- Atomic claim decomposition — Compound claims are auto-split into individual verifiable facts. "Tesla had $96B revenue and 1.8M deliveries" becomes two atomic claims, each verified independently.
- Hybrid retrieval combining keyword and semantic matching — For each claim, keyword matching finds lexical matches and dense embeddings find semantic matches from source text. Rankings are fused to catch paraphrased evidence that keyword matching alone misses (e.g., "prevents fabricated answers" matching "reduces hallucinations"). Premium tier only, with graceful keyword-only fallback.
- Semantic evidence reranking — Top candidates per claim are reranked by a purpose-built verification model trained on 1.4M+ claim-evidence pairs that improves with every query. Selects the best supporting evidence, applies contradiction penalties and paraphrase boosts.
- Multi-provider search — Parallel search across multiple providers for broader source diversity. More independent sources = stronger cross-reference = higher confidence.
- Domain authority scoring — 10,000+ domains across 5 tiers (institutional
.gov/.edu→ major news → tech journalism → community → low-quality). Dynamic scoring that improves from real verification data. - Source quote verification — LLM-extracted quotes verified against actual page text using multi-strategy matching.
- Cross-source consensus — Each claim verified against all available page texts. Claims supported by 3+ independent domains get "strong consensus". Single-source claims flagged as "weak".
- Contradiction detection — Claim pairs analyzed for semantic conflicts using topic overlap and contradiction classification. Detected contradictions surfaced in the response and penalize confidence.
- Multi-pass consistency — In thorough mode, claims are cross-checked across independent extraction passes. Claims confirmed by both passes get boosted; inconsistent claims are penalized.
- Auto-calibrated confidence — Multi-factor confidence formula auto-adjusts from real user feedback. Predicted confidence aligns with actual accuracy over time. Factors: verification rate, domain authority, source count, consensus, domain diversity, claim grounding, source recency, and citation depth.
- Per-claim evidence retrieval — Weak claims get targeted search queries generated by LLM, then searched individually across all providers. Each claim gets its own evidence pool instead of sharing the same corpus.
- Counter-query verification — Verified claims are stress-tested with adversarial "what would disprove this?" search queries. If counter-evidence is found, claim confidence is penalized.
Claims include verified, verificationScore, consensusCount, and consensusLevel fields. Sources include verified, authority, urlHealth, and integrity. Detected contradictions, a citationHealth summary, and a contentRisk summary are returned at the top level. Agents can use these fields to make trust decisions programmatically.
Graceful fallback: When premium keys are not set, the system runs keyword-only verification. Semantic retrieval and reranking are transparent premium enhancements — no degradation, no errors.
Depth Modes
Three depth levels control research thoroughness:
# Thorough mode
curl -X POST https://lastsearch.ai/api/browse/answer \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ls_xxx" \
-d '{"query": "What is quantum computing?", "depth": "thorough"}'
# Deep mode (uses premium features)
curl -X POST https://lastsearch.ai/api/browse/answer \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ls_xxx" \
-d '{"query": "Compare CRISPR approaches for sickle cell disease", "depth": "deep"}'
Deep mode runs iterative think-search-extract-evaluate cycles: each step performs gap analysis to identify what's missing, generates targeted follow-up queries, and merges claims/sources across steps with a final re-verification pass. It targets a confidence threshold of 0.85 (DEEP_CONFIDENCE_THRESHOLD) and runs up to 3 follow-up steps (MAX_FOLLOW_UP_STEPS, 4 total including the initial pass). Uses semantic reranking, multi-provider search, and multi-pass consistency. Each deep query costs 3x quota (100 deep queries/day). When quota is exhausted, deep mode gracefully falls back to thorough. Without a LastSearch key, deep mode also falls back to thorough.
Deep mode responses include reasoningSteps showing the multi-step research process (step number, query, gap analysis, claim count, confidence per step).
Streaming API
Get real-time progress with per-token answer streaming. The streaming endpoint sends Server-Sent Events (SSE) as each pipeline step completes. Deep mode steps are grouped by research pass for clean progress display:
curl -N -X POST https://lastsearch.ai/api/browse/answer/stream \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ls_xxx" \
-d '{"query": "What is quantum computing?"}'
Events: trace (progress), sources (discovered early), token (streamed answer text), result (final answer), done.
Retry with Backoff
All external API calls (search providers, LLM, page fetching) automatically retry on transient failures (429 rate limits, 5xx server errors) with exponential backoff and jitter. Auth errors (401/403) fail immediately — no wasted retries.
Research Memory (Sessions)
Persistent research sessions that accumulate knowledge across multiple queries. Later queries automatically recall prior verified claims, building deeper understanding over time.
Sessions require a LastSearch API key (
ls_xxx) for identity and ownership. Get a free key at lastsearch.ai/dashboard. For MCP, setLASTSEARCH_API_KEYenv var. For Python SDK, passapi_key="ls_xxx". For REST API, useAuthorization: Bearer ls_xxx.
# Python SDK
session = client.session("quantum-research")
r1 = session.ask("What is quantum entanglement?") # 13 claims stored
r2 = session.ask("How is entanglement used in computing?") # 12 claims recalled!
knowledge = session.knowledge() # Export all accumulated claims
# Share with other agents or humans
share = session.share() # Returns shareId + URL
# Another agent forks and continues the research
forked = client.fork_session(share.share_id)
# REST API
curl -X POST https://lastsearch.ai/api/session \
-H "Authorization: Bearer ls_xxx" \
-d '{"name": "my-research"}'
# Returns session ID, then:
curl -X POST https://lastsearch.ai/api/session/{id}/ask \
-H "Authorization: Bearer ls_xxx" \
-d '{"query": "What is quantum entanglement?"}'
# Share a session publicly
curl -X POST https://lastsearch.ai/api/session/{id}/share \
-H "Authorization: Bearer ls_xxx"
# Fork a shared session (copies all knowledge)
curl -X POST https://lastsearch.ai/api/session/share/{shareId}/fork \
-H "Authorization: Bearer ls_xxx"
Each session response includes recalledClaims and newClaimsStored. Sessions can be shared publicly and forked by other agents — enabling collaborative, multi-agent research workflows.
Query Planning
Complex queries are automatically decomposed into focused sub-queries with intent labels (definition, evidence, comparison, counterargument, technical, historical). Each sub-query targets a different aspect of the question, maximizing source diversity. Simple factual queries skip planning entirely — no added latency.
Self-Improving Accuracy
The entire verification pipeline improves automatically with usage:
- Domain authority — Dynamic scoring adjusts domain trust scores as evidence accumulates. Static tier scores dominate initially, then real verification rates take over.
- Adaptive verification thresholds — Claim verification thresholds tune per query type based on observed verification rates. Too strict? Loosens up. Too lenient? Tightens.
- Consensus threshold tuning — Cross-source agreement thresholds adapt based on query type performance.
- Confidence weight optimization — The multi-factor confidence formula rebalances weights per query type when user feedback indicates inaccuracy.
- Page count optimization — Source fetch counts adjust based on confidence outcomes per query type.
Feedback Loop
Submit feedback on results to accelerate learning. Agents and users can rate results as good, bad, or wrong — this feeds directly into the adaptive threshold engine.
curl -X POST https://lastsearch.ai/api/browse/feedback \
-H "Content-Type: application/json" \
-d '{"resultId": "abc123", "rating": "good"}'
client.feedback(result_id="abc123", rating="good")
# Or flag a specific wrong claim:
client.feedback(result_id="abc123", rating="wrong", claim_index=2)
Quick Start
Python SDK
pip install lastsearch
from lastsearch import LastSearch
client = LastSearch(api_key="ls_xxx")
# Research with citations
result = client.ask("What is quantum computing?")
print(result.answer)
print(f"Confidence: {result.confidence:.0%}")
for source in result.sources:
print(f" - {source.title}: {source.url}")
# Thorough mode — auto-retries if confidence < 60%
thorough = client.ask("What is quantum computing?", depth="thorough")
# Deep mode — multi-step reasoning with gap analysis (requires LastSearch key)
deep = client.ask("Compare CRISPR approaches for sickle cell disease", depth="deep")
for step in deep.reasoning_steps or []:
print(f" Step {step.step}: {step.query} ({step.confidence:.0%})")
LangChain integration: (PyPI)
pip install langchain-lastsearch
from langchain_lastsearch import LastSearchAnswerTool, LastSearchSearchTool
# Use with any LangChain agent
tools = [
LastSearchAnswerTool(api_key="ls_xxx"), # Verified search with citations
LastSearchSearchTool(api_key="ls_xxx"), # Basic web search
]
# Standalone usage
tool = LastSearchAnswerTool(api_key="ls_xxx")
result = tool.invoke({"query": "What is quantum computing?", "depth": "thorough"})
5 tools available: LastSearchSearchTool, LastSearchAnswerTool (verified), LastSearchExtractTool, LastSearchCompareTool, LastSearchClarityTool (anti-hallucination).
verify — is this true? (CLI)
npx verify-anything "The Eiffel Tower is located in Berlin. It is 330 metres tall."
npx verify-anything https://example.com/article # a page
pbpaste | npx verify-anything # a pasted AI answer
npx verify-anything setup # adds a `verify` MCP tool to your agents
Every claim → ✓ verified / ✗ contradicted / ? unverified with confidence, source, reason and the exact
evidence span judged. Exit code 1 if anything is contradicted. Source: LastSearch-HQ/verify.
MCP Server (Claude Desktop, Cursor, Windsurf)
npx lastsearch setup
Or manually add to your MCP config:
{
"mcpServers": {
"lastsearch": {
"command": "npx",
"args": ["-y", "lastsearch"],
"env": {
"LASTSEARCH_API_KEY": "ls_xxx"
}
}
}
}
Get a free API key at lastsearch.ai/dashboard.
REST API
# Basic query
curl -X POST https://lastsearch.ai/api/browse/answer \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ls_xxx" \
-d '{"query": "What is quantum computing?"}'
# Thorough mode (auto-retries if confidence < 60%)
curl -X POST https://lastsearch.ai/api/browse/answer \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ls_xxx" \
-d '{"query": "What is quantum computing?", "depth": "thorough"}'
# Deep mode (multi-step reasoning)
curl -X POST https://lastsearch.ai/api/browse/answer \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ls_xxx" \
-d '{"query": "Compare CRISPR approaches", "depth": "deep"}'
Self-Host
The MCP server and frontend are open-source and can be run locally. The verification engine is a hosted service — all API requests are processed by the LastSearch cloud infrastructure.
git clone https://github.com/lastsearch-hq/lastsearch.git
cd lastsearch
pnpm install
pnpm dev:web # Run the frontend locally (API calls go to lastsearch.ai)
API Keys
All API access requires a LastSearch API key (ls_xxx). Sign up for free at lastsearch.ai/dashboard.
The free tier includes 100 premium queries/day (or ~33 deep queries/day at 3x cost each). When the quota is reached, queries gracefully fall back to keyword verification (or deep falls back to thorough) — still works, just basic matching. Quota resets every 24 hours. Pro removes all limits.
API responses include quota info when using a LastSearch key:
{
"success": true,
"result": { ... },
"quota": { "used": 12, "limit": 100, "premiumActive": true }
}
Project Structure
/apps/mcp MCP server (stdio transport, npm: lastsearch)
/packages/shared Shared types, Zod schemas, constants
/packages/python-sdk Python SDK (PyPI: lastsearch)
/src React frontend (Vite, port 8080)
/supabase Database migrations
The verification engine (API server) is in a separate private repository (lastsearch-hq/lastsearch-engine) and runs as a hosted service.
API Endpoints
MCP Tools
Python SDK
Async support: AsyncLastSearch with the same API.
Enterprise Search Providers
Use LastSearch with your own data sources instead of — or alongside — public web search. Supports Elasticsearch, Confluence, and custom endpoints with optional zero data retention for compliance.
# Elasticsearch
result = client.ask("What is our refund policy?", search_provider={
"type": "elasticsearch",
"endpoint": "https://es.internal.company.com/kb/_search",
"authHeader": "Bearer es-token-xxx",
"index": "docs",
})
# Confluence
result = client.ask("PCI compliance process?", search_provider={
"type": "confluence",
"endpoint": "https://company.atlassian.net/wiki/rest/api",
"authHeader": "Basic base64-creds",
"spaceKey": "ENG",
})
# Zero data retention (nothing stored, cached, or logged)
result = client.ask("Patient protocols", search_provider={
"type": "elasticsearch",
"endpoint": "https://es.hipaa.company.com/medical/_search",
"authHeader": "Bearer token",
"dataRetention": "none",
})
# REST API — enterprise search
curl -X POST https://lastsearch.ai/api/browse/answer \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ls_xxx" \
-d '{
"query": "What is our refund policy?",
"searchProvider": {
"type": "elasticsearch",
"endpoint": "https://es.internal.company.com/kb/_search",
"authHeader": "Bearer es-token-xxx",
"index": "docs"
}
}'
Response Structure
Every answer includes structured fields for programmatic trust decisions:
{
"answer": "Quantum computing uses qubits...",
"confidence": 0.82,
"shareId": "abc123def456",
"effectiveDepth": "thorough",
"claims": [
{
"claim": "Qubits can exist in superposition",
"sources": ["https://en.wikipedia.org/wiki/Qubit"],
"verified": true,
"verificationScore": 0.87,
"consensusCount": 3,
"consensusLevel": "strong"
}
],
"sources": [
{
"url": "https://en.wikipedia.org/wiki/Qubit",
"title": "Qubit - Wikipedia",
"domain": "en.wikipedia.org",
"quote": "A qubit is the basic unit of quantum information...",
"verified": true,
"authority": 0.70
}
],
"contradictions": [
{
"claimA": "Quantum computers are faster for all tasks",
"claimB": "Quantum advantage only applies to specific problems",
"topic": "quantum computing performance",
"nliConfidence": 0.89
}
],
"reasoningSteps": [
{ "step": 1, "query": "quantum computing basics", "gapAnalysis": "Initial research pass", "claimCount": 8, "confidence": 0.65 },
{ "step": 2, "query": "quantum computing vs classical comparison", "gapAnalysis": "Missing classical vs quantum comparison", "claimCount": 14, "confidence": 0.82 }
],
"trace": [
{ "step": "Search Web", "duration_ms": 423, "detail": "5 results" },
{ "step": "Fetch Pages", "duration_ms": 1205, "detail": "4 pages" }
],
"quota": { "used": 12, "limit": 50, "premiumActive": true }
}
Key fields:
confidence— evidence-based score (0-1), not LLM self-assessedshareId— unique ID for sharing this result (use with/browse/share/:id)effectiveDepth— actual depth used ("fast","thorough", or"deep") — may differ from requested depth due to fallbackclaims[].verified— whether the claim was verified against source textclaims[].consensusLevel—"strong"(3+ sources),"moderate", or"weak"contradictions— detected conflicts between claims (with confidence score)reasoningSteps— deep mode only: multi-step research iterations with gap analysistrace— execution timeline for debugging and monitoringquota— premium quota usage (LastSearch key users only):used,limit,premiumActive
Examples
See the examples/ directory for ready-to-run agent recipes:
Agent Recipes
Tutorials
Environment Variables
These are for running the MCP server or frontend locally. The verification engine runs as a hosted service and does not require local configuration.
Tech Stack
- API: Node.js, TypeScript, Fastify, Zod
- Search: Multi-provider (parallel search across sources)
- Parsing: @mozilla/readability + linkedom
- AI: LLM via OpenRouter
- Caching: Redis or in-memory with intelligent TTL (time-sensitive queries get shorter TTL)
- Frontend: React, Tailwind CSS, shadcn/ui, Framer Motion
- Verification: Hybrid keyword + semantic matching with evidence reranking
- MCP: @modelcontextprotocol/sdk
- Python SDK: httpx, Pydantic
- Database: Supabase (PostgreSQL)
Agent Skills
Pre-built skills that teach AI coding agents (Claude Code, Codex, Cursor, etc.) when and how to use LastSearch:
npx skills add lastsearch-hq/lastsearch-skills
Community
- Discord — questions, feedback, showcase
- GitHub Issues — bugs, feature requests
Contributing
See CONTRIBUTING.md for setup instructions, coding conventions, and PR process.
License
This project uses an open-core model:
See the LICENSE file for details on this repository.