Skip to content

Bot ingest: R2 + KB pipeline for uploads, live-step streaming endpoint - #9

Merged
KrishnaSSH merged 1 commit into
mainfrom
bot-ingest-pipeline
Sep 6, 2026
Merged

KrishnaSSH merged 1 commit into
mainfrom
bot-ingest-pipeline

Conversation

@KrishnaSSH

Copy link
Copy Markdown
Member

What

  1. /api/bots/ingest now runs the full document pipeline. When a linked user sends a PDF, the bytes are fetched once, replied to synchronously as structured JSON (as before), and in the background pushed through:

    • queueKbIngest → R2 → chunk → embeddings → Pinecone (memory graph) → kb_documents D1 rows
    • queueExtraction → R2 → PDF→JSON → auto draft invoice → doc_extracts D1 rows

    Response gains { kb: { queued: [...] } } so the bot can say "added to your knowledge base".

  2. POST /api/bots/ingest/stream — SSE. Emits step events as the finance agent calls tools, then done with the answer. Lets bots show progress instead of a spinner. Writes a bot_events audit row. Falls back to the Workers-AI one-shot for unlinked users.

  3. Migration renumber — 0014_bot_link_compat.sql → 0016 (collided with 0014_org_currency.sql).

To deploy

wrangler d1 migrations apply grayoffice-db --remote
npm run deploy

Note

main currently fails npm run build on pre-existing missing deps (@tabler/icons-react, liveline, glimm) — unrelated to this PR, but blocks deploy until fixed.

Paired with discord.grayoffice PR (live-streaming-ask).

🤖 Generated with Claude Code

- /api/bots/ingest: a linked user's PDFs are fetched once, replied to
  synchronously as JSON, and pushed in the background through queueKbIngest
  (chunk -> embeddings -> Pinecone memories) + queueExtraction (PDF -> JSON ->
  draft invoice), each writing its own D1 rows. Response gains { kb: { queued } }.
- /api/bots/ingest/stream: SSE 'step' events as the finance agent calls tools,
  then a 'done' event with the answer, so bots can show progress instead of a
  spinner. Writes a bot_events audit row.
- rename 0014_bot_link_compat.sql -> 0016 (0014 collided with 0014_org_currency)
@KrishnaSSH
KrishnaSSH merged commit 45fa3c0 into main Sep 6, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant