Skip to content

Commit

Permalink
add back creative results limit/logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed May 4, 2024
1 parent 39c2a7f commit 30a6b36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export default class TRAPIQueryHandler {
'INFO',
null,
`Execution Summary: (${KGNodes}) nodes / (${kgEdges}) edges / (${results}) results; (${resultQueries}/${queries}) queries${cached ? ` (${cached} cached qEdges)` : ''
} returned results from(${sources.length}) unique API${sources.length === 1 ? 's' : ''}`,
} returned results from (${sources.length}) unique API${sources.length !== 1 ? 's' : ''}`,
).getLog(),
new LogEntry('INFO', null, `APIs: ${sources.join(', ')} `).getLog(),
];
Expand Down
11 changes: 9 additions & 2 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class InferredQueryHandler {
path: string;
predicatePath: string;
includeReasoner: boolean;
CREATIVE_LIMIT: number;
constructor(
parent: TRAPIQueryHandler,
queryGraph: TrapiQueryGraph,
Expand All @@ -67,6 +68,7 @@ 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 @@ -586,7 +588,11 @@ export default class InferredQueryHandler {
new LogEntry(
'INFO',
null,
`Final result count: ${Object.keys(combinedResponse.message.results).length}`,
[
`Final result count`,
Object.keys(combinedResponse.message.results).length > this.CREATIVE_LIMIT ? ' (before truncation):' : ':',
` ${Object.keys(combinedResponse.message.results).length}`,
].join('')
).getLog(),
);
}
Expand All @@ -595,7 +601,8 @@ 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;
});
// prune kg
// trim extra results and prune kg
response.message.results = response.message.results.slice(0, this.CREATIVE_LIMIT);
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 30a6b36

Please sign in to comment.