From a94aebc559a3f2d8743ec104c9d0052e6d40feec Mon Sep 17 00:00:00 2001 From: Johannes Kiesel Date: Fri, 8 Nov 2024 11:10:30 +0100 Subject: [PATCH] Allo for source exclusion --- README.md | 2 +- src/systems/generative-elastic-system.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 61e212f..4404d32 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Flexible simulation and evaluation framework for generative IR. [![docker workflow](https://img.shields.io/github/actions/workflow/status/webis-de/GenIRSim/ghcr.yml?label=docker)](https://github.com/webis-de/GenIRSim/pkgs/container/GenIRSim) [![license](https://img.shields.io/github/license/webis-de/GenIRSim)](https://github.com/webis-de/GenIRSim/blob/main/LICENSE) -Tested in node 21.7.2 with npm 10.5.0 +Tested in node 21.7.2 with npm 10.9.0 ## Quickstart diff --git a/src/systems/generative-elastic-system.js b/src/systems/generative-elastic-system.js index fc10213..f272540 100644 --- a/src/systems/generative-elastic-system.js +++ b/src/systems/generative-elastic-system.js @@ -5,6 +5,11 @@ import { LLM } from "../llm.js" async function queryElastic(query, searchConfiguration, logbook) { const data = {query: query}; + for (const optionalAttribute of [ "_source" ]) { + if (optionalAttribute in searchConfiguration) { + data[optionalAttribute] = searchConfiguration[optionalAttribute]; + } + } const body = JSON.stringify(data); const headers = new Headers(); headers.append("Content-Type", "application/json"); @@ -15,6 +20,9 @@ async function queryElastic(query, searchConfiguration, logbook) { searchConfiguration.url + "_search?size=" + searchConfiguration.size, params); const responseJson = await response.json(); + if ("error" in responseJson) { + throw new Error("Elasticsearch error: " + JSON.stringify(responseJson)); + } const results = responseJson.hits.hits.map((hit, index) => { const result = Object.assign({}, hit["_source"]); result.key = index + 1; @@ -53,14 +61,16 @@ async function queryElastic(query, searchConfiguration, logbook) { * `variables.userTurn.utterance` * @param {Array} [configuration.preprocessing.requiredKeys] - The properties * that the preprocessing response must have (none by default) + * @param {Object} configuration.search + * @param {string} configuration.search.url - The complete URL of the + * Elasticsearch server's API endpoint (up to but excluding `_search`) * @param {string} configuration.search.query - The Elasticsearch query object * for retrieving results, but every string in it is treated as a template. * Variables are the same as for `configuration.preprocessing.message`, plus: * - `{{variables.preprocessing}}`: The parsed output of the preprocessing (if * preprocessing was performed) - * @param {Object} configuration.search - * @param {string} configuration.search.url - The complete URL of the - * Elasticsearch server's API endpoint (up to but excluding `_search`) + * @param {Array} [configuration.search._source_excludes] - A comma-separated + * list of source fields to exclude from the response * @param {number} configuration.search.size - The number of results to retrieve * @param {Object} configuration.generation * @param {string} configuration.generation.message - Template for the