private String buildContext(Result result) {
        Set<String> fieldsToInclude = getFieldsToInclude(result.getQuery());

        StringBuilder sb = new StringBuilder();
        var hits = result.hits();
        int counter = 1;
        for (var hit: hits) {
            sb.append("document [").append(counter++).append("]:\n");
            hit.fields().forEach((key, value) -> {
                if (fieldsToInclude.isEmpty() || fieldsToInclude.contains(key)) {
                    sb.append(key).append(": ").append(value).append("\n");
                }
            });
            sb.append("\n");
        }
        return sb.toString();
    }
An LLM searcher that uses the RAG (Retrieval-Augmented Generation) model to generate completions.
Prompts are generated based on the search result context.
By default, the context is a concatenation of the fields of the search result hits.

@author lesters
container-search/src/main/java/ai/vespa/search/llm/RAGSearcher.java