Skip to content

Commit

Permalink
remove creative results limit
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed May 2, 2024
1 parent 152f308 commit 39c2a7f
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export interface CombinedResponseReport {
querySuccess: number;
queryHadResults: boolean;
mergedResults: { [resultID: string]: number };
creativeLimitHit: boolean | number;
}

// MatchedTemplate, but with IDs, etc. filled in
Expand All @@ -52,7 +51,6 @@ export default class InferredQueryHandler {
path: string;
predicatePath: string;
includeReasoner: boolean;
CREATIVE_LIMIT: number;
constructor(
parent: TRAPIQueryHandler,
queryGraph: TrapiQueryGraph,
Expand All @@ -69,7 +67,6 @@ export default class InferredQueryHandler {
this.path = path;
this.predicatePath = predicatePath;
this.includeReasoner = includeReasoner;
this.CREATIVE_LIMIT = process.env.CREATIVE_LIMIT ? parseInt(process.env.CREATIVE_LIMIT) : 500;
}

get queryIsValid(): boolean {
Expand Down Expand Up @@ -263,7 +260,6 @@ export default class InferredQueryHandler {
querySuccess: 0,
queryHadResults: false,
mergedResults: {},
creativeLimitHit: false,
};
let mergedThisTemplate = 0;
const resultIDsFromPrevious = new Set(Object.keys(combinedResponse.message.results));
Expand Down Expand Up @@ -428,9 +424,6 @@ export default class InferredQueryHandler {
}
report.querySuccess = 1;

if (Object.keys(combinedResponse.message.results).length >= this.CREATIVE_LIMIT && !report.creativeLimitHit) {
report.creativeLimitHit = Object.keys(newResponse.message.results).length;
}
span.finish();
return report;
}
Expand Down Expand Up @@ -550,7 +543,7 @@ export default class InferredQueryHandler {
// make query and combine results/kg/logs/etc
handler.setQueryGraph(queryGraph);
await handler.query();
const { querySuccess, queryHadResults, mergedResults, creativeLimitHit } = this.combineResponse(
const { querySuccess, queryHadResults, mergedResults } = this.combineResponse(
i,
handler,
qEdgeID,
Expand All @@ -564,23 +557,6 @@ export default class InferredQueryHandler {
mergedResultsCount[result] =
result in mergedResultsCount ? mergedResultsCount[result] + countMerged : countMerged;
});
// log to user if we should stop
if (creativeLimitHit) {
stop = true;
const message = [
`Addition of ${creativeLimitHit} results from Template ${i + 1}`,
Object.keys(combinedResponse.message.results).length === this.CREATIVE_LIMIT ? ' meets ' : ' exceeds ',
`creative result maximum of ${this.CREATIVE_LIMIT} (reaching ${
Object.keys(combinedResponse.message.results).length
} merged). `,
`Response will be truncated to top-scoring ${this.CREATIVE_LIMIT} results. Skipping remaining ${
subQueries.length - (i + 1)
} `,
subQueries.length - (i + 1) === 1 ? `template.` : `templates.`,
].join('');
debug(message);
combinedResponse.logs.push(new LogEntry(`INFO`, null, message).getLog());
}
span.finish();
} catch (error) {
handler.logs.forEach((log) => {
Expand Down Expand Up @@ -610,11 +586,7 @@ export default class InferredQueryHandler {
new LogEntry(
'INFO',
null,
[
`Final result count`,
Object.keys(combinedResponse.message.results).length > this.CREATIVE_LIMIT ? ' (before truncation):' : ':',
` ${Object.keys(combinedResponse.message.results).length}`,
].join(''),
`Final result count: ${Object.keys(combinedResponse.message.results).length}`,
).getLog(),
);
}
Expand All @@ -623,8 +595,7 @@ export default class InferredQueryHandler {
response.message.results = Object.values(combinedResponse.message.results).sort((a, b) => {
return b.analyses[0].score - a.analyses[0].score ? b.analyses[0].score - a.analyses[0].score : 0;
});
// trim extra results and prune kg
response.message.results = response.message.results.slice(0, this.CREATIVE_LIMIT);
// prune kg
response.description = `Query processed successfully, retrieved ${response.message.results.length} results.`;
this.pruneKnowledgeGraph(response);
// get the final summary log
Expand Down

0 comments on commit 39c2a7f

Please sign in to comment.