feat: Add vector search to SearXNG search provider

chore: remove unnecessary type annotation in web.ts
This commit is contained in:
n4ze3m 2024-12-01 17:02:09 +05:30
parent 5687517238
commit 0226de7c39
2 changed files with 11 additions and 3 deletions

View File

@ -30,7 +30,7 @@ export const searxngSearch = async (query: string) => {
} }
const isJSONMode = await isSearxngJSONMode() const isJSONMode = await isSearxngJSONMode()
const results = isJSONMode const results = isJSONMode
? await searxngJSONSearch(searxngURL, query) ? await searxngJSONSearch(searxngURL, query)
: await searxngWebSearch(searxngURL, query) : await searxngWebSearch(searxngURL, query)
@ -79,8 +79,17 @@ export const searxngSearch = async (query: string) => {
const chunks = await textSplitter.splitDocuments(docs) const chunks = await textSplitter.splitDocuments(docs)
const store = new MemoryVectorStore(ollamaEmbedding) const store = new MemoryVectorStore(ollamaEmbedding)
await store.addDocuments(chunks) await store.addDocuments(chunks)
const resultsWithEmbeddings = await store.similaritySearch(query, 3)
return store const searchResult = resultsWithEmbeddings.map((result) => {
return {
url: result.metadata.url,
content: result.pageContent
}
})
return searchResult
} }
const searxngJSONSearch = async (baseURL: string, query: string) => { const searxngJSONSearch = async (baseURL: string, query: string) => {

View File

@ -50,7 +50,6 @@ export const getSystemPromptForWeb = async (query: string) => {
} else { } else {
const searchProvider = await getSearchProvider() const searchProvider = await getSearchProvider()
//@ts-ignore
search = await searchWeb(searchProvider, query) search = await searchWeb(searchProvider, query)
} }