Skip to content

fix(kotlin): match pathMatcher against paths relative to the traversed directory - #6378

Open
Lubaoshuai wants to merge 1 commit into
langchain4j:mainfrom
Lubaoshuai:6074-kotlin-relativize-glob
Open

Lubaoshuai wants to merge 1 commit into
langchain4j:mainfrom
Lubaoshuai:6074-kotlin-relativize-glob

Conversation

@Lubaoshuai

Copy link
Copy Markdown
Contributor

Issue

Fixes #6074

Change

The Kotlin loadDocuments extension matched the paths emitted by Files.walk directly against the pathMatcher. Those paths are absolute (rooted at the configured directory), so relative globs such as glob:*.txt never matched anything and the call silently returned an empty list.

This diverges from FileSystemDocumentLoader, which documents (on three public overloads) that each file path is converted from absolute to relative — relative to directoryPath — before being matched, and which relativizes in loadDocuments(Stream, PathMatcher, Path, DocumentParser).

The Kotlin extension now calls path.relativize(file) before matching (paths are still passed to FileSystemSource in absolute form, so loading is unchanged).

Test

Added Should loadDocuments with a relative pathMatcher to AsyncDocumentLoaderTest: recursive load of the existing asyncDocumentLoaderTest resources with glob:*.txt now returns exactly the top-level file1.txt (previously: empty list).

mvn -pl langchain4j-kotlin -am test: all module tests pass.

…d directory

loadDocuments matched the paths emitted by Files.walk (absolute for the
configured directories) directly against the pathMatcher, so relative
globs such as 'glob:*.txt' never matched and the call silently returned
an empty list. FileSystemDocumentLoader documents the opposite contract:
paths are relativized against the directory before matching.

Relativize each walked path against the traversed directory before
matching and add a regression test with a relative glob.

Fixes langchain4j#6074

This branch has not been deployed

No deployments
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.

[BUG] Kotlin loadDocuments ignores relative glob patterns passed as pathMatcher

1 participant