liveBook · Manning

Corpus

As explained in Software Testing with Generative AI

A corpus is a curated collection of documents or other information assembled for retrieval and analysis.

A corpus is a collection of documents or data assembled so a retrieval system can search it for context relevant to a prompt. In RAG, the corpus supplies the material added to an LLM request instead of requiring every document to be included manually. section 10.2.1 section 11.1

A useful corpus supports retrieval by providing:

  • Relevant documents, such as labeled HTML pages, code, documentation, database entries, raw metrics, or user stories. section 10.2.1 section 11.2.1
  • A retrieval process that compares a query with corpus items and selects the closest match for prompt insertion. section 11.1 section 11.2.1
  • A relevance rule that limits context to useful documents, helping avoid context-window limits and irrelevant prompt content. section 11.1 section 10.2.1

Testing-risk corpus

A folder of user-story text files can form a corpus for a testing assistant. Given “I want test ideas for deleting bookings,” retrieval can select the story describing a DELETE request with a booking ID, status codes, and optional cookie authentication. The selected story is inserted into a prompt that asks an LLM to suggest testing risks. section 11.1 section 11.2.1

public static List<String> loadFilesFromResources(String folderPath)        #1
➥throws IOException {                                                      #1
    List<String> fileContents = new ArrayList<>();                          #1
  
    ClassLoader classLoader = CompletedRAGDemo.class.getClassLoader();      #2
    File folder = new File(classLoader.getResource(folderPath).getFile());  #2
  
  
    for (File file : folder.listFiles()) {                                  #3
        if (file.isFile()) {                                                #3
            String fileContent = FileUtils.readFileToString(file, "UTF-8"); #3
                fileContents.add(fileContent);                              #3
        }                                                                   #3
    }                                                                       #3
  
  
    return fileContents;                                                    #4
}

The listing shows a Java method that loads every file from a resources folder into a list, creating a simple document corpus for later querying. section 11.2.1

How Software Testing with Generative AI covers it

How deep it goes
Explains corpus contents, relevance selection, context-window rationale, file loading, and cosine-distance matching.
Examples
Uses labeled HTML pages, user-story files, booking API requirements, and Java resource-folder loading as concrete corpus examples.
What you can do after
Build it from scratch by loading documents, matching a query with cosine distance, and placing the closest document into a prompt.
How it connects
Connects corpora to retrieval-augmented generation, prompts, large language models, context windows, cosine distance, and user stories.

Also explained in

Compare how 4 books explain corpus →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.