ChloeDB
Apps

chloedb-grants: Grant Finder on ChloeDB

Reference, rendered from docs/chloedb/grants.md.

These docs follow main, which can be ahead of the latest release, 0.3.11 (its docs): a change made after it says so where it is described.

On this page
  1. Run it
  2. Tables
  3. The API
  4. Tests

A demo. chloedb-grants shows what ChloeDB can do; it is not part of ChloeDB's releases or their promises. It is tested on a train of its own (the Demos workflow, .github/workflows/demos.yml), outside CI's required check, and the command center marks it as a demo (compatibility).

chloedb-grants helps a small nonprofit find grants and write the applications. It keeps every open federal grant from Grants.gov's public API in ChloeDB, ranks them against the organization's mission, keeps a pipeline of the ones it goes after, and drafts each section of an application from the organization's own writing, citing it.

  • Find. Every posted and forecast opportunity, ranked against the mission and any words typed, by one statement: rrf(bm25(title, :q), bm25(synopsis, :q), similarity(emb, :v), …) with the mission and the words as the vector's text. Grants the organization cannot apply for (by Grants.gov's applicant types, applicants && :elig), that have closed, or that close too soon or pay too little are left out; facets count agencies and categories. Each result shows how well it fits and the words it shares with the mission.
  • Pipeline. Saved, Drafting, Submitted, Won and Not funded, with each move kept in the row's history, and the words drafted so far.
  • Library. The organization's own writing: past applications, annual reports, program descriptions, budgets. Upload a PDF, Word file (.docx), HTML, Markdown or text, or paste; each is cut into passages of about seventy words, kept with their own vectors (gr_passages).
  • Write. Each section of an application (a standard six, or the funder's own read from the announcement) is drafted by llm() from the passages closest to it, picked by the same kind of statement over the library, and cites them as [n]. Ticking and unticking sources changes what the next draft is written from. Shorten brings a draft within the section's words.
  • Check. A draft is checked against what the funder asks: by the app (within the words, every source cited, no source cited that it was not given, every number found in a source), and by llm() reading the funder's guidelines as a program officer would. The guidelines are the full announcement, read from the opportunity's attachments on Grants.gov (PDF, Word, or HTML, following NIH's pages), or pasted.
  • Export. The application as Markdown, with its sources.

It starts with an example organization (Eastbay Harvest, a food bank) and a dozen passages of its writing, so that every page has something on it; Remove the example clears them, and the mission page takes the organization's own.

Like Hacker News and Sound Explorer, it is a program of its own, in Rust, that talks to chloedb-server over HTTP only, and the command center shows it as an app (Apps → Grant Finder).

Run it#

(cd chloedb-server && cargo build --release --bin chloedb-server)
cd chloedb-grants && cargo build --release
ANTHROPIC_API_KEY=... target/release/chloedb-grants serve --local ./grants-data --server-bin ../chloedb-server/target/release/chloedb-server

serve --local DIR starts a chloedb-server with its database in DIR (it passes on ANTHROPIC_API_KEY, which llm() needs), makes the tables and the example organization, syncs Grants.gov (about 1,400 open opportunities, fetched in under half a minute) and syncs again every --sync-hours (6), and lists the app as grants; open http://127.0.0.1:7700 and go to Apps → Grant Finder. The server fetches the embedding model (potion-retrieval-32M, --model for another) the first time a field names it. Without a key, finding, the pipeline and the library work, and drafting and the model's checks answer with the server's error.

Against a server or a cluster that runs elsewhere:

chloedb-grants init --chloedb http://coordinator:7700 --key "$CHLOEDB_KEY"
chloedb-grants sync --chloedb http://coordinator:7700 --key "$CHLOEDB_KEY"
chloedb-grants serve --chloedb http://coordinator:7700 --key "$CHLOEDB_KEY" --token "$GRANTS_TOKEN" --listen 0.0.0.0:7890
chloedb-server ... --app grants=http://grants-host:7890     # with CHLOEDB_APP_TOKEN=$GRANTS_TOKEN

sync fetches what is new, what changed (by the opportunity's revision) and what is older than --stale-hours (72), at most --sync-limit a run (5000), and marks the rows Grants.gov no longer lists as closed.

--public serves the page at / and its API to anyone, without the token, within --per-minute requests a minute from one address (240), and refuses calls from another site's pages; only a sync needs the token. Drafts, shortening and the model's checks are counted against --llm-per-day (500) and --llm-per-hour (40) calls. A public demo has one organization, shared by its visitors.

On Kubernetes, deploy/k8s.yaml runs the server and the app on a node of the demo pool, with the database on the node's own disk; it is the one at grants.chloetech.ai.

Tables#

table a row is its vector
gr_grants an opportunity: number, title, agency and department, status (posted, forecasted, closed), categories, instruments, applicant types, synopsis, eligibility, dates, award ceiling and floor, total, awards, cost sharing, assistance listings, contact, the announcement's attachments, revision emb, of the title and synopsis (OPTIONS(embed = 'title, synopsis'))
gr_org the organization: name, mission, place, budget, applicant type
gr_pipeline a grant gone after: stage, the ask, a note, the history of moves
gr_docs, gr_passages a document of the library, and its passages emb, of the document's name and the passage
gr_guidelines a grant's guidelines: the announcement's text, where it came from, and what it asks
gr_sections a section of a grant's application: name, words, guidance, where it came from
gr_drafts a section's draft: text, the passages picked, the last checks
gr_sync the last sync: listed, fetched, closed, failed, how long

The API#

Every answer carries queries, the SQL it ran, for the page's SQL drawer. Writes are POST.

route what
GET /v1/find?q=&dept=&cat=&status=&within=&min=&eligible=&limit= grants ranked against the mission and the words, with facets
GET /v1/grant/:id a grant, how it fits, whether the organization can apply, its pipeline row
GET /v1/pipeline, POST /v1/pipeline/:id the pipeline by stage; {stage, ask, note} moves a grant (an empty stage removes it)
GET, POST /v1/org the organization
GET /v1/library, POST /v1/library/paste, POST /v1/library/upload?file=&name= the library; paste {name, text}, or upload a file as the body (20 MB at most)
POST /v1/library/doc/:id/delete, POST /v1/library/example/drop remove a document, or the example
GET /v1/editor/:id?ord= a grant's sections, the section's draft, its sources and the passages to pick from
POST /v1/draft/:id/:ord, /v1/shorten/:id/:ord, /v1/check/:id/:ord, /v1/text/:id/:ord draft from {picks}, shorten, check, save the text
GET, POST /v1/sections/:id, POST /v1/sections/:id/read the sections, set by hand or read from the guidelines
GET, POST /v1/guidelines/:id, POST /v1/guidelines/:id/fetch the guidelines, pasted or read from the announcement
GET /v1/export/:id the application as Markdown
GET /v1/status, POST /v1/sync the counts, the last sync and the model's calls today; a sync now (token only)

Tests#

cargo test runs the app against a real chloedb-server (CHLOEDB_SERVER_BIN, or one built in ../chloedb-server) with a made-up Grants.gov of four opportunities and a made-up Messages API: the sync, finding with each filter, eligibility, the pipeline, the library (paste, a Word file, a refused format), the editor, drafting with citations, checks that catch a made-up number, shortening, reading the announcement through a page that refreshes, sections read from it, the export, and that the API needs the token and refuses another site's pages.