Skip to content
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

Clean up function args #979

Merged
merged 1 commit into from
Dec 28, 2024
Merged

Conversation

zeroliu
Copy link
Collaborator

@zeroliu zeroliu commented Dec 28, 2024

Clean up constructor and function arguments when singleton can be used. See inline comments for more details

Tests

  • QA vault works
  • @vault, @web, @youtube, @pomodoro works
  • removing files index works
  • custom db search command works
  • updating exclusion path works

@@ -68,13 +66,12 @@ export default class CopilotPlugin extends Plugin {
// Always have one instance of sharedState and chainManager in the plugin
this.sharedState = new SharedState();

this.vectorStoreManager = new VectorStoreManager(this.app);
await this.vectorStoreManager.waitForInitialization();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to explicitly block onload. The initialization will happen in the background and all public methods will wait for initialization.


// Directly return the content assuming it's structured as expected
if (rewrittenQueryObject && "content" in rewrittenQueryObject) {
return rewrittenQueryObject.content;
return rewrittenQueryObject.content as string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a type issue here but this refactor doesn't have any logic change. It should be safe to cast to string and keep the same type definition as before.

private indexOps: IndexOperations;
private eventHandler: IndexEventHandler;
private initializationPromise: Promise<void>;
private lastKnownSettings: CopilotSettings | undefined;
public dbOps: DBOperations;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbOps shouldn't be accessed before the initialization finishes

@@ -26,11 +26,18 @@ export default class VectorStoreManager {
this.setupSettingsSubscription();
}

static getInstance(): VectorStoreManager {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made this singleton. It was only instantiated once

};

subscribeToSettingsChange(() => {
this.initializationPromise = reinitialize();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to wait for initialization again when settings change causes the singleton to reinitialize

@@ -121,15 +132,16 @@ export default class VectorStoreManager {
this.dbOps.onunload();
}

public async getOrInitializeDb(embeddingsAPI: Embeddings): Promise<Orama<any>> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have another place to initialize DB. initialize method be the one that instantiate db


constructor(
private dbOps: DBOperations,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hybridRetriever becomes a lot easier to use after taking out these singleton instance args

@zeroliu zeroliu force-pushed the zero/fix-function-args branch from 4a52bd3 to 042726f Compare December 28, 2024 20:33
@zeroliu zeroliu requested a review from logancyang December 28, 2024 20:41
@zeroliu zeroliu marked this pull request as ready for review December 28, 2024 20:41
@logancyang
Copy link
Owner

Nice! Thanks for the cleanup! ✅

@logancyang logancyang merged commit d5bf5dc into logancyang:master Dec 28, 2024
2 checks passed
@logancyang logancyang mentioned this pull request Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants