Raven-1/NOTICES.md
Kevin Hu 82c76a82a9
feat(knowledge): read every format, show what the index holds, and let an agent search it (#489)
<img width="2318" height="1448" alt="image"
src="https://github.com/user-attachments/assets/bca71d69-4972-420c-b14e-c8cf74a17de9"
/>

## Summary

Everything a knowledge base could not read, and the pieces it cut them
into
saying what they are.

**Reading a PDF.** A PDF records glyphs at coordinates; whether they are
a
heading, a table cell or a running footer is inferred from how they
look. There
are now two readers. The geometric one infers structure from type size
and
position and needs nothing but the file. The other asks deepdoc's
models, ported
into `raven/knowledge/parser/deepdoc`: a layout model that says what
each region
is, a detector and recognizer that read a page carrying no text at all,
and a
table-structure model that rebuilds a grid from a picture of one. 
 Detecting boxes around text the file already spells
out exactly costs an inference pass per page to learn less, and
recognising it
costs accuracy.

The layout graph answers with a shape its own postprocessing
raises on, and its classes are DocLayout-YOLO's order rather than the
list
Both were established by running the model, and the label order is
pinned by a test.

**Tables go in as tables.** `<table>` is the only shape that keeps what
a grid
states -- which column a cell stood under, which cells are merged, which
row is
the header -- and it is the shape a model reads a table in, which is
what these
chunks are for. PDF, Word and PowerPoint all state their merges exactly,
and
they now survive as `colspan` and `rowspan`. The flat form this replaces
had to
repeat a header standing over two columns across both of them, because
there was
nowhere to record a span; it had no callers left afterwards and is gone.
Two
deviations from upstream, both about what the string is for: every
cell's text
is escaped, where upstream interpolates it raw and a cell holding a `<`
produces
markup that is no longer a table, and the span attributes are written
only where
there is a span, where upstream emits `<td  >` for every ordinary cell.

**A picture of where each chunk came from.** A chunk is a few hundred
words with
a page number on it, which is enough to cite and not enough to answer
whether
the parser read the page correctly. So every PDF chunk that knows where
it sits
carries one image: the regions it covers, cropped out of the rendered
pages and
stacked. here they are already structured in the parser's element spans,
so
the markers would only put text nobody wrote into the thing being
embedded.
The panel draws a chunk's tables as tables, parsed and
rebuilt as elements rather than injected: a person can rewrite any piece
from
that same panel, so what comes back from the store is user input however
it got
there.

**The page that reads them.** Upstream retired the knowledge page while
this
branch was out; it is rebuilt against the new architecture, and the half
that
never existed is the one a reader needs -- what a document actually
became once
it was cut and embedded. Documents sit in one-level folders and arrive
by four
routes: a file, a folder, a URL, a written note. Adding and indexing are
two
calls on the contract and nothing drains that queue on its own, so a
page that
stopped after the first left every upload saying Queued for good.

Opening a file takes the whole page: the document on the left, the
pieces the
index holds of it on the right. The left half is the file drawn as its
own
pages rather than framed by the browser's PDF viewer, which reads where
to open
once and answers to nothing afterwards -- and which nothing can be drawn
on.
Pages are rendered once and kept, and the region a piece was cut from is
washed
over the page it came from, placed in fractions of the page so the
picture's
own scale never enters the arithmetic. Clicking a piece takes the file
there;
double-clicking opens it for rewriting.

The pieces can be searched, filtered by state, turned on and off,
deleted,
rewritten and added to, one at a time or in a batch. Every one of those
was
already on the contract with no reader for it. A base's settings are
back and
fuller: how many pieces a search returns, how documents are cut, and how
much
prose comes with a table or a figure. The embedding model is a picker
while the
base holds no pieces and a stated fact once it does -- moving it then is
the
collection made again at the new width and every document re-cut, which
is not
a thing a panel does by being saved.

**An agent can read them.** The retrieval engine was there and nothing
could
reach it: no agent had a tool that opened a library. A reader now points
a
conversation at bases from the composer, the way they pin a working
directory,
and the selection rides in the same place -- the session's metadata,
bound
around the turn.

The tool takes a query and never a base. The scope is the reader's
choice, so a
model cannot reach material nobody offered it, and it is withheld where
nothing
was picked rather than offered and refused. A hit says which document
and page
it came from, because a hit a reader cannot place is a hit they cannot
check --
and the passages are pressable in the transcript, walking into the base,
the
document, the folder it is filed under and then the piece. A citation a
reader
cannot follow is a claim they have to take on trust, and the whole point
of
searching their own material is that they can go and look.

**The word segmenter and the resources.** `raven.core.Tokenizer` is
Infinity's
`rag_tokenizer`, ported: a forward and backward maximum match over a
dictionary
trie, with stemming and lemmatisation on the latin path. XGBoost is not
carried
over. None of the data lives in git -- the dictionary, the NLTK corpora
and the
ONNX graphs run to about a hundred megabytes, so `make fetch-resources`
on an
install and an optional Docker layer behind `RAVEN_RESOURCES` both point
at one
script. A checkout that could not reach the network still works, and
every
feature that reads this data says so when asked.

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

Run on macOS against Python 3.12, with the deepdoc weights fetched (the
model
tests skip without them):

```
uv run pytest                        27450 passed, 111 skipped, 3 failed
npm run test --prefix ui-web          3276 passed
npm run test --prefix ui-tui          2106 passed
npm run type-check --prefix ui-web    clean (tsc)
npm run lint --prefix ui-web          clean (4 pre-existing hook warnings)
make lint-python                      clean (ruff check + format)
make lint-types                       clean (ty)
make lint-imports                     10 contracts kept, 0 broken
make check-source-language            clean
make check-large-files                clean
make build-ui                         built, both boot snapshots match
node ui-web/scripts/check-css.mjs     clean
node ui-web/scripts/check-class-namespace.mjs  clean
```

The three Python failures are not this branch's and were each confirmed
on the
base alone: one asks a host without LibreOffice to refuse a render and
this host
has LibreOffice installed, and two simulation cases fail on an
unmodified
checkout of the base commit.

The RPC contract was regenerated for both consumers and both match it
(`npm run gen --prefix ui-web`, `npm run gen:rpc --prefix ui-tui`, then
`gen:check`). The page's boot snapshots and region goldens were
refreshed where
the composer bar gained a button, and each records that button and
nothing else.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed

## Risk

A PDF's tables, and a Word or PowerPoint file's, are now indexed as HTML
rather
than as header-prefixed lines. Chunk text changes shape for those
documents, so
a base indexed before this and searched after it holds both forms until
its
documents are reindexed; retrieval keeps working either way, because
both forms
are text. The same applies to how much prose a table or a figure carries
with
it: the setting now reaches as far as it says, where before it stopped
at the
nearest paragraph, so a chunk cut before this keeps the narrower context
until
its document is rebuilt. Rolling back is reverting the branch and
reindexing.

The deepdoc models are optional. An install that never ran `make
fetch-resources` reads PDFs geometrically, exactly as before, and says
so when
the models are asked for by name. Nothing here reaches the network at
request
time.

Chunk crops and rendered pages are written at index time and on first
view, both
under the state directory rather than in the repository, and both are
deleted
with their document. A page is immutable for the life of its document
id, so
the route serving them caches; the document route does not. All three
routes
take ids and no path, and the two image routes answer under the
strictest
sandbox in the tree.

What an agent may search is the reader's choice and nothing else. The
tool takes
no base argument, so a model cannot name one, and it is absent from the
schema
entirely for a conversation that named none -- a lane nobody pointed at
a base
is unchanged by this branch. The bases a session carries are stored
beside its
working directory and travel no further.

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

## Related Issues

N/A

---------

Co-authored-by: Claude (claude-opus-5) <noreply@anthropic.com>
2026-10-12 19:05:16 +08:00

268 lines
16 KiB
Markdown

# Third-Party Notices
Raven is licensed under the Apache License 2.0. It incorporates code from the
projects below (MIT unless noted). Their copyright notices and license texts are
retained in `LICENSES/`.
## nanobot (base agent runtime)
- Source: https://github.com/HKUDS/nanobot
- Copyright (c) 2025 nanobot contributors
- License: MIT — see `LICENSES/MIT-nanobot.txt`
- Scope: forked at v0.1.5.post3; modified throughout `raven/`
(agent/, bus/, channels/, cli/, config/, cron/, providers/, session/,
skills/, templates/, utils/).
## hermes-agent (TUI layer)
- Source: https://github.com/NousResearch/hermes-agent
- Copyright (c) 2025 Nous Research
- License: MIT — see `LICENSES/MIT-hermes-agent.txt`
- Vendored at commit: `dd0923bb89ed2dd56f82cb63656a1323f6f42e6f` (2026-05-12)
- Scope: full `ui-tui/` import (169 files / ~31.6k LOC TypeScript src
+ ~26.3k LOC vendored `@hermes/ink`). Modifications: branding replaced
with minimal Raven component, gateway stubbed (no real IPC; deferred
to `tui-ipc-bridge` L2), 36+ env vars renamed `HERMES_*` → `RAVEN_*`,
literal Hermes/Nous brand strings replaced throughout `ui-tui/src/`,
SPDX/Copyright headers added to every ≥ 50 LOC source file.
## ink (vendored via `@hermes/ink`)
- Upstream source: https://github.com/vadimdemedes/ink
- Copyright (c) Vadym Demedes, Sindre Sorhus, and ink contributors
- License: MIT — see `LICENSES/MIT-ink.txt`
- Scope: hermes-agent ships its own fork of community ink at
`ui-tui/packages/hermes-ink/` (~26.3k LOC). Raven inherits this
vendor verbatim (package name `@hermes/ink` preserved for attribution).
Triple attribution chain (ink contributors → Nous Research hermes-ink
→ EverMind modifications) is encoded in the 5-line SPDX header of
every substantial file under `ui-tui/packages/hermes-ink/src/`.
The fork policy (hard fork, no upstream sync, fixes land in-tree) lives
in `ui-tui/packages/hermes-ink/README.md`.
## RAGFlow (retrieval engine)
- Upstream source: https://github.com/infiniflow/ragflow
- Copyright (c) 2025 InfiniFlow and RAGFlow contributors
- License: Apache-2.0
- Scope: `raven/knowledge/_naive_chunker.py` is a port of RAGFlow's
`naive_merge_docx` and the delimiter helpers around it (`rag/nlp/__init__.py`,
`rag/nlp/delim.py`, `common/token_utils.py`): the delimiter field syntax, the
build-then-merge arrangement, the rule that a table or a figure stands as its
own chunk, and the tokenizer the sizes are counted with.
`raven/knowledge/parser/_tables.py` carries `__compose_table_content` and the
cell taxonomy from `deepdoc.parser.docx_parser`, and composes a grid as an
HTML table the way `TableStructureRecognizer.construct_table` does.
`raven/knowledge/parser/excel_parser.py` follows `deepdoc.parser.excel_parser`
in shape: a row labelled by its header is the unit, the sheet name travels
with a row when it names something, and the same file renders whole as HTML
tables or as markdown. `raven/knowledge/_vision.py` carries a port of the
figure-describing prompt (`rag/prompts/vision_llm_figure_describe_prompt.md`
and its with-context variant), and `raven/knowledge/parser/image_parser.py`
follows `deepdoc.parser.figure_parser.VisionFigureParser` in what it asks a
vision model for and in carrying the prose around a figure into the call.
`raven/knowledge/parser/ppt_parser.py` follows
`deepdoc.parser.ppt_parser.RAGFlowPptParser`: shapes read in the order they
sit on the slide rather than the order the file lists them, bulleted
paragraphs marked by their indent, group shapes walked through, and one
string per slide. `raven/knowledge/parser/deepdoc/` is a port of RAGFlow's
`deepdoc.vision` package -- the preparation operators and the detector
postprocessing (`operators.py`, `postprocess.py`), the ONNX wrapper and its
box sorting and overlap arithmetic (`recognizer.py`), the layout classifier
and its garbage filter (`layout_recognizer.py`), the text detector and
recognizer (`ocr.py`), and the table-structure model with the row, column and
span reconstruction around it (`table_structure_recognizer.py`). The parser
package's layout follows `deepdoc.parser` the same way; each module names its
origin in its own docstring. `ui-web/src/assets/file-icon/` is eighteen of
RAGFlow's own file-format icons (`web/src/assets/svg/file-icon/`): a page
outline with the format's letters on a coloured band. The drawings are
byte-for-byte theirs; each file gained the one trailing newline this repo's
hooks require, and nothing else. `raven/knowledge/_crops.py` follows
`RAGFlowPdfParser.crop` in what it produces: one image a chunk, with the
regions that chunk covers cut out of the rendered pages and stacked top to
bottom. The chunk reader takes its shape from the same product: the file
drawn as a column of page images (`raven/rpc/knowledge_pages.py`) with the
region a chunk was cut from washed over in colour, beside the list of what
the index holds.
- Modifications: rewritten rather than vendored -- it carries no RAGFlow
import, is written against this package's Section and Chunk shapes, keeps the
positional metadata RAGFlow discards, and answers a tokenizer failure with an
estimate rather than with zero. The spreadsheet parser reads the formats with
the standard library and LibreOffice instead of openpyxl and pandas, which
this install does not carry, and renders every sheet where RAGFlow's markdown
renders the first. The figure path drops the OCR ladder RAGFlow puts in front
of the vision model: a figure is a picture, and reading the words printed on
one instead of describing it is the wrong answer however cheap. The two
prompts are merged into one template whose context sections are omitted when
there is no context, rather than rendered empty. The vision package drops the
remote-inference client, the Ascend NPU variant and the CUDA branch that
pip-installs torch at import to ask whether a GPU exists; it holds one session
per model for the process rather than one per device behind a semaphore, runs
on the CPU unless an operator opts in, retries a failed inference three times
rather than a hundred thousand, and carries the label order the published
weights actually answer with -- RAGFlow's own list is for an older export and
disagrees on every index. `deepdoc/_pipeline.py` arranges the three models the
way `deepdoc.parser.pdf_parser.RAGFlowPdfParser` does, with one difference:
where RAGFlow detects text boxes on every page, this uses the file's own text
layer wherever there is one and runs the detector and recognizer only on the
pages that have nothing to read. The crops differ in two ways as well. RAGFlow
writes each region's coordinates into the chunk's own text as `@@...##` markers
and parses them back out with a regex, because its chunk is a bare string with
nowhere else to keep them; here they are already structured in the parser's
`elements` spans, so the markers would only put text nobody wrote into the
thing being embedded. And RAGFlow renders every page of a document up front
and holds them while it is processed, where this visits the pages once each
and releases each before the next, so the peak is one page however long the
document. Two things about the table HTML differ as well. Every cell's text
and every caption is escaped, where upstream interpolates them raw -- the text
comes off a page, and the string is indexed, handed to a model and rendered in
a panel, so a cell holding a `<` otherwise produces markup that is no longer a
table. And the span attributes are quoted and written only where there is a
span, where upstream emits `<td >` for every ordinary cell. The Word parser
reaches the same HTML through `_tables.html_table` rather than through the
vision stack, and states its merges as `colspan` and `rowspan`: the flat form
it used to produce had to repeat a straddling cell across the columns it
covered, because there was nowhere to record a span. Of RAGFlow's forty-one
file icons only the nineteen whose formats a parser here accepts were taken:
an icon for a format nothing can ingest is a drawing nobody can ever see, and
the handful this tree takes that RAGFlow draws no icon for fall back to a
page carrying their own suffix. The slide parser reads the
OOXML package with the standard library instead of python-pptx, which this
package does not carry, and reads slide order through the presentation's own
relationships -- python-pptx resolves that, and the part names do not. Its
sections are marked atomic, so one slide is one chunk; RAGFlow returns the
slides as strings and leaves the merging to its caller.
## Infinity (rag tokenizer)
- Upstream source: https://github.com/infiniflow/infinity
- Copyright (c) 2025 InfiniFlow and Infinity contributors
- License: Apache-2.0
- Scope: `raven/core/tokenizer.py` is a port of `infinity/rag_tokenizer.py`
from the Infinity python SDK -- the dictionary trie, the forward and backward
maximum-matching passes, the scored resolution of ambiguous spans, and the
latin path's stemming and lemmatisation. It is the tokenizer RAGFlow indexes
Chinese with.
- Modifications: ported rather than depended on -- the package it ships in is a
vector database's client, and a knowledge base that segments Chinese should
not need a second vector store installed. The class is renamed `Tokenizer`,
the dictionary is resolved under `raven/core/res/` and a missing one raises
with the command that fetches it rather than calling `exit(1)`, nltk reads
the corpora fetched beside it rather than a machine-wide path, the CLI demo
is dropped, and the full-width punctuation class is written as escapes for
the source-language gate.
## Infinity resource files (word dictionary)
- Upstream source: https://github.com/infiniflow/resource
- Copyright (c) 2023 InfiniFlow
- License: MIT
- Scope: `rag/huqie.txt`, the word-and-frequency dictionary the tokenizer
segments against. Not vendored: it is 8 MB, and `scripts/fetch_resources.py`
downloads it into `raven/core/res/` at install time.
- Modifications: none. The file is used as published; the trie beside it is
built locally because the published one is serialised against a different
libdatrie and does not load.
## deepdoc models (document vision)
- Upstream source: https://huggingface.co/InfiniFlow/deepdoc
- Copyright (c) 2025 InfiniFlow
- License: Apache-2.0 for the repository. The weights are not all under it --
see the per-file table below, which is what each file's own embedded
metadata states rather than what the repository does.
- Scope: the ONNX weights the PDF parser runs -- text detection (`det.onnx`),
text recognition (`rec.onnx`) with its character set (`ocr.res`), page layout
(`layout.onnx`) and table structure (`tsr.onnx`).
- **Not published by this project, but baked into the default container.**
Two artifacts, and they differ:
The wheel carries no weight. They are gitignored (`.gitignore`,
`raven/knowledge/res/`), the wheel's include list names no `.onnx` and no
`res/`, and `python -m raven.resources` fetches them from Hugging Face into
an already-installed `raven/knowledge/res/` when an operator runs
`make fetch-resources`. An install that skips that step reads PDFs
geometrically and never loads them.
The Docker image does. `Dockerfile` defaults `RAVEN_RESOURCES=1` and runs
that same fetch at build time, so the image `docker/docker-compose.yml`
builds -- the one the top-level README's install instructions produce --
contains all four, `layout.onnx` among them. The default is deliberate and is
explained where it is set: a container that first reached Hugging Face when
somebody uploaded a PDF would fail in a deployment with no egress, long after
the build that could have said so.
No registry push exists in `.github/workflows/`, so this project publishes no
such image; the compose file builds one on the operator's own machine, which
is their own fetch happening inside a container rather than beside one.
Pushing that image to a registry, or shipping an appliance built from it, is
redistribution -- and that is the moment `layout.onnx`'s licence field stops
being a footnote. `RAVEN_RESOURCES=0` builds an image without any of them;
what it costs is PDF layout and Chinese segmentation, both of which report
their own absence.
What each file says about itself, read out of its ONNX metadata:
| file | author | license, as stamped | trained on |
|---|---|---|---|
| `layout.onnx` | Ultralytics | **AGPL-3.0** | YOLOv10m-doclayout, a mixed document-layout set |
| `tsr.onnx` | Ultralytics | Apache-2.0 | PubTables-1M |
| `det.onnx` | -- (PaddlePaddle export) | not stamped | PaddleOCR detection |
| `rec.onnx` | -- (PaddlePaddle export) | not stamped | PaddleOCR recognition |
`layout.onnx` is the one that matters and its metadata is self-contradictory:
the licence field reads `AGPL-3.0 License` and the URL beside it points at
RAGFlow's own LICENSE, which is Apache-2.0. AGPL-3.0 is also what Ultralytics'
export tooling stamps by default on anything built with it, so the field may
record the tool rather than the publisher's intent. This repository cannot
settle which was meant, and does not try to: the fact is recorded here so that
anyone who builds an image or an appliance with the weights already fetched
into it -- which is redistribution, where a plain `pip install` is not --
decides it with the upstream rather than discovering it.
- Modifications: none to the weights. The three genre-specific layout variants
published beside them are not fetched, and neither are the `.ort`
serialisations, because nothing here selects between the first or reads the
second.
## agentscope (web-service framework)
- Upstream source: https://github.com/agentscope-ai/agentscope
- Copyright (c) 2025 Alibaba Group and AgentScope contributors
- License: Apache-2.0 - see `LICENSES/Apache-2.0-agentscope.txt`
- Adopted at commit: `c84fd1a54dcc207257a8d616ff63b65470febc95` (the RavenX fork
of agentscope 2.0.4, itself based on upstream `4cb58320`)
- Scope: the vendored tree it was adopted into (`ui-webui/service/agentscope/`,
284 files supplying the retired web service's FastAPI app, Redis storage,
RAG/knowledge-base managers and sub-agent DAG machinery) was removed with
`ui-webui` itself. What remains in this repository, and what this notice is
now about, is the code adopted FROM it and rewritten in place:
`raven/knowledge/_types.py`, `raven/knowledge/_chunker.py`,
and `raven/knowledge/parser/` (the `ParserBase` contract and the plain-text
parser; the package layout follows RAGFlow's `deepdoc.parser` and the Word
parser is our own). Each names its origin in its own module docstring. A
fourth module, `dag_projection`, carried derived code until it was removed
for having no importer; nothing of it remains.
- Modifications: the three modules above are rewritten rather than vendored --
they take agentscope's chunking, parsing and DAG-projection logic and nothing
else, and they carry no agentscope import. The attribution stays because the
derivation does; the licence text is kept at
`LICENSES/Apache-2.0-agentscope.txt`. The retired tree's own PROVENANCE.md
went with it, and its per-subsystem trimming rationale is only of interest to
a tree that no longer exists.
# External Runtime Tools (not vendored)
The following tools are invoked by Raven via `subprocess` calls but are
**not bundled or redistributed** as part of any Raven release artifact.
Their attribution here is supply-chain hygiene, not a license requirement.
Users install them separately through their respective package managers.
## tui-use (TUI autotest harness Tier 1 backend)
- Source: https://github.com/onesuper/tui-use
- Copyright (c) 2026 Wei Hong (onesuper)
- License: MIT
- Install: `npm install -g tui-use` (npm package `tui-use`)
- Scope: invoked by `tests/tui/autotest/runner.py::Harness` for PTY-driven
TUI subprocess control. Selected as Tier 1 backend per Day 0 spike
(2026-05-20) — all 5 acceptance gates S1-S5 passed. Raven does NOT
vendor, redistribute, or modify `tui-use` source.
- Fallback contingency: if upstream maintenance halts (>90 days no push) or
a severe incompatibility surfaces, the vendor-or-pivot decision follows the
L0-L3 ladder recorded with the original evaluation.
Vendoring (path L1) Vendoring (path L1) would require moving
`tui-use` to `vendor/tui-use/` and adding its LICENSE to `LICENSES/` plus
updating this section's "Scope" line to "vendored" — same pattern as
`hermes-agent` above.