Repository navigation
contextual: a title from front matter, and nothing the chunk already holds - #1
Merged
Merged
Conversation
…holds
The extractive context took a document's first line as its title and
prepended it to every chunk. On real corpora that went wrong three ways:
- Front matter. A page that opens with YAML front matter got the title
"---", and its best sentence could be a front-matter line
("--- — title: Harbour Pilot Manual"). Every page of a docs site built
with front matter was affected.
- One-line documents. The title is the whole document, so the chunk was
sent with its own text prepended: every memory fact in an agentty
history (213 of 213 passages) reached the model twice.
- First chunks. The heading is both the title and inside the chunk, so it
was repeated; and a later chunk could get the heading line ("# Title")
as its best sentence, after the title itself.
The title is now front matter's `title:` when present, else the first
non-empty line after the front matter. Front matter is not a source of
sentences. The title is left out when the chunk contains it, and a heading
that is the title is not a candidate sentence: the rule the best sentence
already followed.
A full build (tests, examples, bench) printed 39 -Wunused-result warnings under GCC 16, whose libstdc++ marks std::expected [[nodiscard]]. Compiling the same files with the library's own -Wall -Wextra -Wpedantic shows four more (three -Wcomment, one -Wunused-variable) that the default build hides, because only the ragcpp target gets those flags. CI's -Werror lane covers only ragcpp too, so none of them failed a build. - Examples check every add() and build() through a small must() that prints the error and exits. They are what users copy, so they should not show failures being dropped. - ragcpp_rcp_tests gets -Wno-unused-result (/wd4834 on MSVC), the same fixture idiom ragcpp_tests already has. - The two benches cast their setup results to void. - include/rag/rcp/convert.hpp: an unused `double b`. - Three usage comments ended a line in a backslash, which continued the comment onto the next line; each command is now on one line.
… line
Review follow-ups to the front-matter title:
- The title check was a substring match, so a chunk that only mentioned a
short title ("see Usage above") lost its title context. A chunk now holds
the title only when one of its lines is the title: its heading, its
front-matter key, or the whole of a one-line document.
- Front matter: a UTF-8 byte-order mark before the fence, TOML front
matter (+++, title = "..."), and a YAML block title (title: >) taking
its first line instead of ">".
- A setext underline (=== or ---) is heading markup, never a best
sentence; the setext heading text is the title, as before.
Tests cover each shape, a quoted title with a colon, an unclosed fence,
the mid-sentence mention and a setext heading.
Each example carried its own copy of must(). They now include examples/must.hpp, and the include blocks are back as they were plus that one line. The code_retrieval_bench usage comment is split across two lines again, without the backslash that made -Wcomment fire.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
contextual: a title from front matter, and nothing the chunk already holds
What was wrong
When no LLM contextualizer is set,
contextualize()usesextractive_context(). It prepends the document's title and its best-overlapping sentence to every chunk before indexing. The title was simply the document's first line. On real corpora that goes wrong in three ways:pilot.md)---, or--- — title: Harbour Pilot ManualHarbour Pilot Manual — The harbour pilot boards…lighthouse.md)---/--- — title: Lighthouse KeepingLighthouse Keepingcrane.md)# headingpage, first chunk (tides.md)Tide Table Notes, which the chunk already starts withEach row is the real output of
extractive_context()fromupstream/mainand this branch, on the same four files.In agentty, which uses this as its retrieval backend:
--- —and a fragment of a table row.The context also feeds
indexed_text(), so the noise went into BM25 and the embeddings as well as the text the model reads.The change
src/text/contextual.cpp:Title. It comes from front matter when there is any, otherwise from the first non-empty line after it, without heading marks. Supported front matter:
title:, quoted or not, including a block title (title: >, which takes its first line);title = "..."between+++fences;An unclosed fence isn't treated as front matter.
Front matter isn't prose. It's no longer a source of candidate sentences.
Nothing the chunk already holds is repeated.
# Title) and a setext underline (===,---) are never chosen as the best sentence.An LLM
Contextualizer, when one is set, is unchanged.Tests
tests/test_main.cpp, next tocontextualize_adds_situating_context:extractive_context_reads_the_title_from_front_matter:title:wins, and the context holds no---, front-matter key or# heading;title:key, the first line after the front matter is used;extractive_context_does_not_repeat_what_the_chunk_holds:The existing contextual tests pass unchanged: their documents have no front matter, and their chunks don't contain the title.
No warnings outside the library
A full build (tests, examples, bench) printed 39
-Wunused-resultwarnings with GCC 16. Compiling the same files with the library's own-Wall -Wextra -Wpedanticturns up 4 more, which the default build doesn't show because only theragcpptarget gets those flags. CI didn't catch any of them because its-Werrorjob only coversragcpp.-Wunused-result. libstdc++ 16 marksstd::expected[[nodiscard]], so every discardedadd()/build()result warned.must()inexamples/must.hpp, which prints the error and exits. Examples are what users copy, so they shouldn't show failures being dropped.ragcpp_rcp_testsgets the same-Wno-unused-resultthatragcpp_testsalready has (/wd4834on MSVC).void.-Wunused-variable(under-Wall) ininclude/rag/rcp/convert.hpp: an unuseddouble b.-Wcomment(under-Wall): usage comments ending in a backslash, which carried the comment onto the next line.code_retrieval_benchusage keeps its two lines, without the backslash.tests/test_main.cppstill has three-Wmissing-field-initializerswarnings under-Wextra(lines 1838, 1876, 3396). They were already there before this branch and fall outside it.Note for hosts that persist an index
The stored chunk context changes, so an index saved with an earlier version keeps the old contexts until it's rebuilt. agentty will raise its index version when it bumps the submodule.