Home / Docs / Documents

Add, update and delete documents

Send documents as JSON: an id, the text, and any metadata you want to filter on. A write is answered only once it's safely stored.

Add or update documents

POST /api/collections/{name}/docs with up to 10,000 documents. Sending an id that's already there replaces that document: searches see only the newest version.

Shell
curl -X POST https://stackgrep.com/api/collections/contracts/docs \
  -H "Authorization: Bearer $STACKGREP_KEY" \
  -d '{"docs": [
        {"id": "acme/msa-2024.txt", "text": "MASTER SERVICES AGREEMENT ...",
         "meta": {"customer": "acme", "year": 2024, "signed": true}},
        {"id": "globex/nda.txt", "text": "MUTUAL NON-DISCLOSURE AGREEMENT ..."}
      ]}'
# {"written": 2, "searchable": false}
NameTypeWhat it does
docs[].idstringYour id for the document: up to 512 bytes, on one line. Slashes are fine (a file path makes a good id).
docs[].textstringThe text to search, up to 2,000,000 bytes.
docs[].metaobjectOptional. Values to filter on, like customer or type. Strings are kept as they are; numbers and booleans as JSON writes them (2024 becomes "2024"); nulls are dropped.
waitbooleanOptional. true: searchable before we answer. Otherwise searchable within a few seconds.

Either way, the answer comes only once the documents are durably stored: if you get 200, they're kept. Writes that arrive within 50 ms of each other are stored together, so many small writes in parallel are cheap and fast. If storing fails you get 503 and nothing was written; send the same request again.

Read a document

GET /api/collections/{name}/docs/{id} returns the newest version of a document whole, with its metadata. Search results give you the ids.

Shell
curl https://stackgrep.com/api/collections/contracts/docs/acme/msa-2024.txt \
  -H "Authorization: Bearer $STACKGREP_KEY"
Response
{"id": "acme/msa-2024.txt", "text": "MASTER SERVICES AGREEMENT ...",
 "meta": {"customer": "acme", "year": "2024", "signed": "true"}}

Delete documents

POST /api/collections/{name}/delete with up to 10,000 ids. Deleted documents stop showing up in searches right away.

Shell
curl -X POST https://stackgrep.com/api/collections/contracts/delete \
  -H "Authorization: Bearer $STACKGREP_KEY" -d '{"ids": ["globex/nda.txt"]}'
# {"written": 1, "searchable": true}

Writes cost 1 credit for each 1,000 documents or 10 MB of text in a request, whichever is more. Reading a document costs 1. See pricing.

Try it on your own documentsExact and regex search for your agents, from one API. Or see the engine on npm's source first.