Package sk.iway.iwcm.rag.indexing
Class MarkdownContentExtractor
java.lang.Object
sk.iway.iwcm.rag.indexing.MarkdownContentExtractor
- All Implemented Interfaces:
ContentExtractor<String>
Prepares Markdown for chunking while preserving document structure and code examples.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddHeadingContext(String text, String title, List<SlidingWindowChunker.Chunk> chunks) Adds the document title and the shared heading hierarchy of each passage to its embedding input.extractText(String markdown) Removes front matter, link destinations, image paths, and hidden HTML before chunking.extractTitle(String markdown, String sourcePath) Uses the first level-one heading outside comments and code, falling back to the relative file path.Returns the entity type identifier (e.g., "document").
-
Constructor Details
-
MarkdownContentExtractor
public MarkdownContentExtractor()
-
-
Method Details
-
extractText
Removes front matter, link destinations, image paths, and hidden HTML before chunking. Link labels, existing image descriptions, headings, lists, tables, and code examples are retained.- Specified by:
extractTextin interfaceContentExtractor<String>- Parameters:
markdown- source Markdown, ornull- Returns:
- cleaned Markdown, or an empty string for null input
-
extractTitle
Uses the first level-one heading outside comments and code, falling back to the relative file path.- Parameters:
markdown- source Markdown, ornullsourcePath- non-null relative path used when no heading is found- Returns:
- heading or fallback path, truncated to at most 512 characters
-
addHeadingContext
public List<String> addHeadingContext(String text, String title, List<SlidingWindowChunker.Chunk> chunks) Adds the document title and the shared heading hierarchy of each passage to its embedding input. Merged sibling subsections use their common parent. Passage bodies remain unchanged, code headings are ignored, and overlapping passages retain context at their own source positions.- Parameters:
text- cleaned Markdown with normalized newlines, as supplied to the chunkertitle- document title or source-path fallbackchunks- ordered chunks with offsets in the trimmed source text- Returns:
- contextual embedding inputs in chunk order
-
getEntityType
Description copied from interface:ContentExtractorReturns the entity type identifier (e.g., "document").- Specified by:
getEntityTypein interfaceContentExtractor<String>
-