-
Notifications
You must be signed in to change notification settings - Fork 25
use cached context #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
use cached context #458
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideSwitches validation AI analysis serialization to use a cached R5 FhirContext instance instead of constructing a new one on each request, to reduce overhead while acknowledging potential memory implications. Sequence diagram for cached FhirContext usage during AI validation analysissequenceDiagram
participant HttpServletRequest as HttpServletRequest
participant ValidationProvider as ValidationProvider
participant LLMConnector as LLMConnector
participant FhirContext as FhirContext
participant IParser as IParser
HttpServletRequest->>ValidationProvider: validate(theRequest)
activate ValidationProvider
ValidationProvider->>LLMConnector: getConnector(cliContext)
activate LLMConnector
LLMConnector-->>ValidationProvider: connector
deactivate LLMConnector
ValidationProvider->>FhirContext: forR5Cached()
FhirContext-->>ValidationProvider: fhirContext
ValidationProvider->>FhirContext: newJsonParser()
FhirContext-->>ValidationProvider: parser
ValidationProvider->>IParser: setPrettyPrint(true)
IParser-->>ValidationProvider: parser
ValidationProvider->>IParser: encodeResourceToString(oo)
IParser-->>ValidationProvider: json
ValidationProvider->>LLMConnector: interpretWithMatchbox(contentString, json)
LLMConnector-->>ValidationProvider: aiResult
ValidationProvider->>ValidationProvider: addAIIssueToOperationOutcome(oo, aiResult)
ValidationProvider-->>HttpServletRequest: OperationOutcome
deactivate ValidationProvider
Class diagram for ValidationProvider AI analysis serialization changeclassDiagram
class ValidationProvider {
+validate(theRequest HttpServletRequest) IBaseResource
+addAIIssueToOperationOutcome(oo OperationOutcome, aiResult String) OperationOutcome
}
class LLMConnector {
+getConnector(cliContext Object) LLMConnector
+interpretWithMatchbox(contentString String, json String) String
}
class FhirContext {
+forR5() FhirContext
+forR5Cached() FhirContext
+newJsonParser() IParser
}
class IParser {
+setPrettyPrint(prettyPrint boolean) IParser
+encodeResourceToString(resource Object) String
}
ValidationProvider ..> LLMConnector : uses
ValidationProvider ..> FhirContext : uses
FhirContext ..> IParser : creates
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- If there are other call sites in this class or module that still use
FhirContext.forR5(), consider switching them toforR5Cached()as well to keep behavior and performance characteristics consistent. - Double-check that
FhirContext.forR5Cached()is safe to use in this context from a configuration perspective (e.g., any custom settings on the non-cached context are not required here), since changing the factory method can subtly affect behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- If there are other call sites in this class or module that still use `FhirContext.forR5()`, consider switching them to `forR5Cached()` as well to keep behavior and performance characteristics consistent.
- Double-check that `FhirContext.forR5Cached()` is safe to use in this context from a configuration perspective (e.g., any custom settings on the non-cached context are not required here), since changing the factory method can subtly affect behavior.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| try { | ||
| LLMConnector openAIConnector = LLMConnector.getConnector(cliContext); | ||
| String json = FhirContext.forR5().newJsonParser().setPrettyPrint(true).encodeResourceToString(oo); | ||
| String json = FhirContext.forR5Cached().newJsonParser().setPrettyPrint(true).encodeResourceToString(oo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember, have we tried to disable pretty-printing? I would result in less tokens for the LLM analyze, but would probably retain all information.
|
I don't think that would be a memory leak, but it was a heavy memory allocation for sure. |
don't recreate everytime an new context but use the cached one (might be a memory leak?)
Summary by Sourcery
Enhancements: