Research
Agent Retrieval HTMLOpen source · Active

agrep

Agent-first search: natural-language queries, domain-aware ranking, and JSONL output for code, legal, docs, and logs.

Overview

agrep is a deterministic query-planning retrieval engine for autonomous agent workflows. Instead of treating retrieval as an opaque vector lookup, it exposes how a natural-language query is planned, ranked, and emitted as structured JSONL that an agent harness can consume without guessing.

Vector-only RAG collapses dissimilar corpora into a single embedding space and hides ranking. agrep keeps domain-aware ranking and query plans inspectable so agents can retrieve code, legal text, documentation, and logs with a stable output contract.

The engine is designed as a tool surface for runtimes such as Lattice: the model asks a question; agrep returns ranked, structured records the harness can bound, audit, and feed back as a projection.

Architecture diagram

01Query
02Plan
03Rank
04JSONL

Natural-language query → explicit plan → domain-aware ranking → structured JSONL for the harness.

Natural-language query in; a visible query plan, domain-aware ranking, and JSONL records out — without collapsing retrieval into a black-box vector search.

Core concepts

1

Query planning

The incoming natural-language question is compiled into an explicit retrieval plan before ranking, so the agent can see what will be searched and why.

2

Domain-aware ranking

Code, legal, documentation, and log corpora are ranked with domain-specific signals rather than a single generic embedding similarity score.

3

Structured JSONL output

Results are emitted as JSON Lines with a stable schema, so harnesses can parse, bound, and trace retrieval without scraping prose.

4

Deterministic retrieval

Given the same corpus and query plan, ranking is inspectable and repeatable — a contrast to stochastic, vector-only RAG pipelines.

Query planner pipeline

1

Query

The agent submits a natural-language question and the target domain (code, legal, docs, or logs).

2

Plan

agrep compiles a retrieval plan: which indexes, filters, and ranking features will run.

3

Rank

Domain-aware scoring produces an ordered candidate set with visible features.

4

Emit

Results are written as JSONL records the harness can ingest, bound, and project back to the model.

Security model

1

Bounded tool output

JSONL is a closed schema, limiting the chance that retrieval dumps unbounded raw files into the model context.

2

Inspectable ranking

Query plans and scores can be audited, so a confused or injected query is easier to detect than in opaque vector search.

3

No hidden side effects

Retrieval is read-oriented: the engine does not execute tools or mutate enterprise systems on the agent's behalf.

Source repository

csehammad/agrep

The implementation is developed openly on GitHub — HTML. The repository is the source of truth for code, examples and documentation.

Open on GitHub