use web worker to run pglite
This commit is contained in:
@@ -60,6 +60,7 @@ export class GeminiProvider implements BaseLLMProvider {
|
||||
: undefined
|
||||
|
||||
try {
|
||||
console.log(request)
|
||||
const model = this.client.getGenerativeModel({
|
||||
model: request.model,
|
||||
generationConfig: {
|
||||
|
||||
@@ -28,12 +28,9 @@ function getDeepResearchCapabilitiesSection(): string {
|
||||
CAPABILITIES
|
||||
|
||||
- You have access to tools that let you search the web using internet search engines like Google to find relevant information on current events, facts, data, and other online content.
|
||||
- Using search_web, you can simulate a human research process: first searching with relevant keywords to obtain initial results (containing URLs, titles, and content snippets).
|
||||
- You should evaluate the relevance and reliability of each search result based on its title and content snippet, then select the most relevant URLs for deeper investigation.
|
||||
- Use fetch_urls_content to retrieve complete webpage content from selected URLs to gain detailed information.
|
||||
- You can conduct multiple rounds of searches and content retrieval (maximum 3 rounds), optimizing your search keywords in each round based on previously gathered information, just as a human would perform deep research.
|
||||
- Synthesize all collected information to answer the user's questions comprehensively, accurately, and in a well-structured manner, citing information sources when appropriate.
|
||||
`
|
||||
- Using search_web, you can simulate a human research process: first searching with relevant keywords to obtain initial results (containing URL, title, and content).
|
||||
- Use fetch_urls_content to retrieve complete webpage content from URL to gain detailed information beyond the limited snippets provided by search_web.
|
||||
- Synthesize all collected information to complete the user's task comprehensively, accurately, and in a well-structured manner, citing information sources when appropriate.`
|
||||
}
|
||||
|
||||
export function getCapabilitiesSection(
|
||||
@@ -45,4 +42,4 @@ export function getCapabilitiesSection(
|
||||
return getDeepResearchCapabilitiesSection();
|
||||
}
|
||||
return getObsidianCapabilitiesSection(cwd, searchWebTool);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,17 @@ Usage:
|
||||
<query>Your search query here</query>
|
||||
</search_web>
|
||||
|
||||
Examples:
|
||||
Examples1:
|
||||
<search_web>
|
||||
<query>capital of France population statistics 2023</query>
|
||||
</search_web>
|
||||
|
||||
Examples2:
|
||||
<search_web>
|
||||
<query>"renewable energy" growth statistics Europe</query>
|
||||
</search_web>
|
||||
|
||||
Examples3:
|
||||
<search_web>
|
||||
<query>react vs angular vs vue.js comparison</query>
|
||||
</search_web>`
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { App } from 'obsidian'
|
||||
import { App, TFile } from 'obsidian'
|
||||
|
||||
import { QueryProgressState } from '../../components/chat-view/QueryProgress'
|
||||
import { DBManager } from '../../database/database-manager'
|
||||
@@ -13,7 +13,8 @@ export class RAGEngine {
|
||||
private app: App
|
||||
private settings: InfioSettings
|
||||
private vectorManager: VectorManager
|
||||
private embeddingModel: EmbeddingModel | null = null
|
||||
private embeddingModel: EmbeddingModel | null = null
|
||||
private initialized = false
|
||||
|
||||
constructor(
|
||||
app: App,
|
||||
@@ -23,7 +24,7 @@ export class RAGEngine {
|
||||
this.app = app
|
||||
this.settings = settings
|
||||
this.vectorManager = dbManager.getVectorManager()
|
||||
this.embeddingModel = getEmbeddingModel(settings)
|
||||
this.embeddingModel = getEmbeddingModel(settings)
|
||||
}
|
||||
|
||||
setSettings(settings: InfioSettings) {
|
||||
@@ -34,16 +35,14 @@ export class RAGEngine {
|
||||
// TODO: Implement automatic vault re-indexing when settings are changed.
|
||||
// Currently, users must manually re-index the vault.
|
||||
async updateVaultIndex(
|
||||
options: { reindexAll: boolean } = {
|
||||
reindexAll: false,
|
||||
},
|
||||
options: { reindexAll: boolean },
|
||||
onQueryProgressChange?: (queryProgress: QueryProgressState) => void,
|
||||
): Promise<void> {
|
||||
if (!this.embeddingModel) {
|
||||
throw new Error('Embedding model is not set')
|
||||
): Promise<void> {
|
||||
if (!this.embeddingModel) {
|
||||
throw new Error('Embedding model is not set')
|
||||
}
|
||||
await this.vectorManager.updateVaultIndex(
|
||||
this.embeddingModel,
|
||||
this.embeddingModel,
|
||||
{
|
||||
chunkSize: this.settings.ragOptions.chunkSize,
|
||||
excludePatterns: this.settings.ragOptions.excludePatterns,
|
||||
@@ -57,7 +56,23 @@ export class RAGEngine {
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
this.initialized = true
|
||||
}
|
||||
|
||||
async updateFileIndex(file: TFile) {
|
||||
await this.vectorManager.UpdateFileVectorIndex(
|
||||
this.embeddingModel,
|
||||
this.settings.ragOptions.chunkSize,
|
||||
file,
|
||||
)
|
||||
}
|
||||
|
||||
async deleteFileIndex(file: TFile) {
|
||||
await this.vectorManager.DeleteFileVectorIndex(
|
||||
this.embeddingModel,
|
||||
file,
|
||||
)
|
||||
}
|
||||
|
||||
async processQuery({
|
||||
query,
|
||||
@@ -78,13 +93,19 @@ export class RAGEngine {
|
||||
if (!this.embeddingModel) {
|
||||
throw new Error('Embedding model is not set')
|
||||
}
|
||||
// TODO: Decide the vault index update strategy.
|
||||
// Current approach: Update on every query.
|
||||
await this.updateVaultIndex({ reindexAll: false }, onQueryProgressChange)
|
||||
|
||||
if (!this.initialized) {
|
||||
await this.updateVaultIndex({ reindexAll: false }, onQueryProgressChange)
|
||||
}
|
||||
const queryEmbedding = await this.getQueryEmbedding(query)
|
||||
onQueryProgressChange?.({
|
||||
type: 'querying',
|
||||
})
|
||||
})
|
||||
console.log('query, ', {
|
||||
minSimilarity: this.settings.ragOptions.minSimilarity,
|
||||
limit: this.settings.ragOptions.limit,
|
||||
scope,
|
||||
})
|
||||
const queryResult = await this.vectorManager.performSimilaritySearch(
|
||||
queryEmbedding,
|
||||
this.embeddingModel,
|
||||
@@ -93,7 +114,8 @@ export class RAGEngine {
|
||||
limit: this.settings.ragOptions.limit,
|
||||
scope,
|
||||
},
|
||||
)
|
||||
)
|
||||
console.log('queryResult', queryResult)
|
||||
onQueryProgressChange?.({
|
||||
type: 'querying-done',
|
||||
queryResult,
|
||||
|
||||
Reference in New Issue
Block a user