Add cqp_query tool
Closes #12 (closed)
Description:
Adds cqp_query, the corpus-search tool. The model writes a CQP query; we run it against the cqp4rdf backend and return the matches as KWIC lines.
What it does
-
Runs CQP queries against
cqp4rdf. -
Returns up to 50 KWIC lines per page, e.g.:
P100065 1(u) gin2 ku3-babbar … 2(u) sze gur [lugal] i3-ag2-e-a mu … -
Each line starts with the source tablet's P-number, so the model can hand it to
get_metadata/get_inscription. -
Endpoint is configurable via
CQP_BASE_URL(defaults to the deployed CDLI endpoint).
Handling the backend's quirks
- Multi-word queries must include a
::join, without one the backend computes a Cartesian product and always times out. The tool blocks un-joined multi-word queries up front with a clear message. - Even with a join, the backend currently times out on most multi-word queries. This is a known backend limitation (documented in the tool description); single-word queries are reliable.
- The three outcomes are worded so the model can't confuse them:
- no matches → "query ran fine, nothing matched, don't retry"
- timeout → "query was too expensive, matches may exist, narrow it and retry"
- bad syntax → upstream error, revise the query