Apache Commons Text is a Java library used here to compare text and identify documentation relevant to a user query in a retrieval-augmented generation workflow. section 11.2.1
The demonstrated relevance workflow:
- Loads a corpus of documents, then compares each document with the query using CosineDistance. section 11.2.1
- Returns the document with the lowest distance score, treating that document as the closest match for prompt context. section 11.2.1
- Supports experimentation with alternative relevance measures, including Levenshtein distance and Jaccard similarity. section 11.2.1
Selecting relevant testing guidance
A Java method iterates through user-story documents, applies CosineDistance to each document and query, tracks the smallest score, and returns the associated document for insertion into a testing-risk prompt. section 11.2.1
<dependencies>
<dependency> #1
<groupId>commons-io</groupId> #1
<artifactId>commons-io</artifactId> #1
<version>2.16.1</version> #1
</dependency>
<dependency> #2
<groupId>org.apache.commons</groupId> #2
<artifactId>commons-text</artifactId> #2
<version>1.12.0</version> #2
</dependency> #2
<dependency> #3
<groupId>dev.langchain4j</groupId> #3
<artifactId>langchain4j-open-ai</artifactId> #3
<version>0.31.0</version> #3
</dependency> #3
Shows the Maven dependency declaration for Apache Commons Text alongside the Java RAG demonstration's other dependencies. section 11.2.1
