Skip to content

fix(ingest): send knowledge text as a knowledge_base item so search returns the text (OSS-70) - #56

Merged
adityamishra-hydradb merged 3 commits into
mainfrom
adityamishra/oss-70-knowledge-text-envelope
Dec 4, 2026
Merged

adityamishra-hydradb merged 3 commits into
mainfrom
adityamishra/oss-70-knowledge-text-envelope

Conversation

@adityamishra-hydradb

@adityamishra-hydradb adityamishra-hydradb commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

For humans

Problem. hydradb ingest --kind knowledge --text "..." stored the text, but search did not return it. Search returned a JSON record with internal fields (acl_snapshot_signature, acl_admission_id, ...) and the text inside it. This is bad context for an LLM, it uses about 5 times more tokens, and it shows internal fields to the user. Linear: OSS-70.

Cause. The CLI sent the text as an app_knowledge item with no kind. The server chunks an item with no kind as its whole JSON record, including the acl_* fields that the server adds.

Fix. The CLI now sends the text as a knowledge_base item, with the text in fields.body_text. The server renders that item as "Title + Content", so search returns only the title and the text. The text also stays in content.text, because hydradb inspect shows it from there (the renderer does not read it, so the chunk does not change). The client id (--source-id), --title, --acl and --no-infer work as before. One file changed in src/.

Proof on prod (a throwaway database in the throwaway org, deleted after the test). The same text, ingested by a 0.2.3 wheel from main (A) and from this branch (B):

A: main B: this PR
chunk {"acl_revision_captured":true,"acl_source_deployment_id":"free","acl_admission_id":"566e…",…,"content":{"text":"Q4 pricing…"}…} (~650 characters) ## Title\n\nGlimmer B\n\n## Content\n\nQ4 pricing for Quuxcorp: the Glimmerfang plan costs 57 dollars per seat per month.
source_type document knowledge_base

Also checked on prod with this branch: the --source-id is kept; list --kind knowledge, update --acl, update --additional-metadata, relations and delete <id> work; --acl user:x hides the item from another principal; a 16 KB text gives 7 normal chunks; no --source-id gives a server id and a clean chunk; re-ingesting an id that an older CLI stored replaces the old JSON chunk.

Not in this PR.

  • hydradb inspect <id> still shows the stored JSON record with the acl_* fields. The server returns that record for every app_knowledge item, so the fix is on the server (/context/inspect should drop the acl_* fields).
  • No CHANGELOG line: PR 55 adds the ## Unreleased section at the same place, so a line here would conflict. Add it after PR 55 merges.

For agents

  • Change: src/hydradb_cli/hydra/client.py, _Context.ingest, knowledge-text branch. The item was {"id", "content": {"text"}}. It is now {"id", "content": {"text"}, "app_kind": "knowledge_base", "app_fields": {"body_text": text}}, plus title, infer: false and acl as before. app_kind / app_fields are the AppKnowledgeModel JSON names, which are already in the simulator allowlist APP_KNOWLEDGE_ITEM_KEYS.
  • Server facts (hydradb-application): ingestion/internal/temporal/activities/chunk.go produceKnowledgeChunks sends an item with AppKind != "" to the app-source renderer, else it chunks the raw file. ingestion/internal/platform/appsource/render.go KnowledgeBaseFields.render uses body_markdown, else body_text. It ignores content.text, so kind alone indexes the title only (tested on prod: chunk ## Title\n\nPricing KB).
  • Why not a documents .md upload (as the MCP does): the server makes a new uuid for a documents upload, so --source-id would stop working for delete and verify (see the docstring of ingest).
  • Commit 665f442 puts content.text back: the live job on a177732 failed inspect.content, inspect.alias.fetch_content and burst.inspect, which read the stored text from content.text. Checked on prod after the change: one chunk (## Title\n\nPemberwick\n\n## Content\n\nThe Pemberwick gateway…) and inspect content.text = the text.
  • Tests: tests/test_wrapper.py::TestIngest::test_ingest_knowledge_text_is_a_knowledge_base_item (new) and tests/e2e/sim/test_simulated.py::test_knowledge_text_ingest_sends_accepted_keys (new expected item). Both fail on main and pass here. make lint and make test pass (1898 passed, 133 skipped).

🤖 Generated with Claude Code

…eturns the text (OSS-70)

`hydradb ingest --kind knowledge --text ...` sent an app_knowledge item with
no kind. The server chunks such an item as its whole JSON record, including
the acl_* fields it stamps on it, so query returned that JSON and not the
text. A knowledge_base item is rendered from its fields, so the CLI now
sends app_kind=knowledge_base with the text in app_fields.body_text. The
client id, title, acl and infer are sent as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: adityamishra-hydradb <[email protected]>
@adityamishra-hydradb

Copy link
Copy Markdown
Contributor Author

@hydra-mira-review review

@adityamishra-hydradb

Copy link
Copy Markdown
Contributor Author

/devin review

@devin-ai-integration

Copy link
Copy Markdown

Starting Devin Review.

Devin Review

@hydra-mira-review

hydra-mira-review Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Mira score 5/5 · 🟢 Good to merge

  • No findings, nothing missing outside this PR, and no high-risk change.

Knowledge text ingested through the CLI now appears in search as a title and content, without internal record fields. The payload uses knowledge_base with app_fields.body_text, while retaining stored text for inspection and preserving existing ingest options.

Before this ships · 1 in place
  • ✅ Accept and render typed knowledge-base items (contract), needed in hydradb-application ingestion API and worker. The description reports production support for app_kind and app_fields, with title-and-body chunks from KnowledgeBaseFields.render.
How this PR works · 2 changes, 1 medium risk, 1 low risk

Knowledge text appeared in search as a JSON record containing internal ACL fields, wasting tokens and exposing implementation details. This PR sends knowledge text as a typed knowledge-base item so the server renders its title and body. It retains the stored text and existing item options.

1. Send knowledge text through the knowledge-base renderer · 🟠 medium risk · src/hydradb_cli/hydra/client.py

Search receives a title and text instead of the stored JSON record. _Context.ingest adds app_kind: knowledge_base and app_fields.body_text, while retaining content.text and existing item options.

Risk: Knowledge-text users would receive rejected ingests, missing search text or raw JSON chunks if the server misinterprets the new fields.

Check:

  • Ingest titled text with a fixed source ID; check that search returns the title and body while inspect retains content.text.
  • Re-ingest an older source ID with --no-infer and an ACL; check replacement and visibility for another principal.

In client.py:380-401.

  1. Supporting changes · 🟢 low risk · tests in test_wrapper.py:142-158, test_simulated.py:382-398.
Requirement check · 3 met, 2 for another PR · from the PR description
  • ✅ Send knowledge text as a knowledge-base item with its body in the renderer's fields (met). _Context.ingest sets app_kind to knowledge_base and places the text in app_fields.body_text.
  • ✅ Keep the stored text available to inspect (met). _Context.ingest retains the original content.text value.
  • ✅ Preserve source IDs, titles, ACLs and the inference refusal (met). _Context.ingest retains id and the existing blocks for title, acl and infer: false.
  • ➖ Remove internal ACL fields from inspect responses (for another PR). The description assigns inspection cleanup to the server's /context/inspect response.
  • ➖ Add a changelog entry (for another PR). The description defers the entry until PR 55 introduces the Unreleased section.
Check by hand · 1
  • Confirm supported server deployments route app_kind=knowledge_base through produceKnowledgeChunks and render app_fields.body_text through KnowledgeBaseFields.render.
⚠️ Other open PRs change the same code · 3

Merge them in order, or check that they agree.

Comment @hydra-mira-review help for commands.

@openhack-agent

openhack-agent Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

OpenHack Summary

Security review of fix(ingest): send knowledge text as a knowledge_base item so search returns the text (OSS-70). 3 changed files; 0 findings at or above the low reporting threshold.

P1: Critical 0   P2: High 0   P3: Medium 0   P4: Low 0

Confidence Score: 5/5

No reportable security findings were detected in this scan.

Security merge-readiness rubric: 1 = critical, 2 = high, 3 = medium, 4 = low, 5 = no reportable findings. This score reflects scan findings, not a guarantee of correctness or complete coverage.

Files Needing Attention: None

Important Files Changed
  • src/hydradb_cli/hydra/client.py (modified)
  • tests/e2e/sim/test_simulated.py (modified)
  • tests/test_wrapper.py (modified)

Last reviewed commit: 665f442 · View review on OpenHack


TIP: Mention @openhack-agent in a PR comment to request a review or ask a question. Use @openhack-agent fix all for every finding, or @openhack-agent fix unresolved threads for open review threads only.

@openhack-agent openhack-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenHack reviewed this commit. See the OpenHack Summary for the confidence score and fix actions.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

…t (OSS-70)

The live tier showed that inspect reads the stored text from content.text,
which the previous commit left empty. The knowledge_base renderer does not
read content.text, so sending the text there too keeps inspect working and
does not change the chunk (checked on prod: one chunk, title and text only).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: adityamishra-hydradb <[email protected]>
@adityamishra-hydradb

Copy link
Copy Markdown
Contributor Author

@hydra-mira-review review

@adityamishra-hydradb

Copy link
Copy Markdown
Contributor Author

/devin review

@devin-ai-integration

Copy link
Copy Markdown

Starting Devin Review.

Devin Review

@adityamishra-hydradb
adityamishra-hydradb merged commit 8231ac1 into main Dec 4, 2026
7 of 8 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.

2 participants