forked from open-webui/open-webui
refac: queryVectorDB renamed to queryCollection
This commit is contained in:
parent
50f7b20ac2
commit
1d0eaec37e
3 changed files with 39 additions and 43 deletions
|
@ -66,13 +66,13 @@ export const uploadWebToVectorDB = async (token: string, collection_name: string
|
|||
|
||||
export const queryVectorDB = async (
|
||||
token: string,
|
||||
collection_names: string[],
|
||||
collection_name: string,
|
||||
query: string,
|
||||
k: number
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${RAG_API_BASE_URL}/query/collections`, {
|
||||
const res = await fetch(`${RAG_API_BASE_URL}/query/collection`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
|
@ -80,7 +80,7 @@ export const queryVectorDB = async (
|
|||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
collection_names: collection_names,
|
||||
collection_name: collection_name,
|
||||
query: query,
|
||||
k: k
|
||||
})
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
getTagsById,
|
||||
updateChatById
|
||||
} from '$lib/apis/chats';
|
||||
import { queryVectorDB } from '$lib/apis/rag';
|
||||
import { queryCollection } from '$lib/apis/rag';
|
||||
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
|
||||
|
||||
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
||||
|
@ -232,17 +232,16 @@
|
|||
processing = 'Reading';
|
||||
const query = history.messages[parentId].content;
|
||||
|
||||
let relevantContexts = await queryVectorDB(
|
||||
localStorage.token,
|
||||
docs.map((d) => d.collection_name),
|
||||
query,
|
||||
4
|
||||
).catch((error) => {
|
||||
let relevantContexts = await Promise.all(
|
||||
docs.map(async (doc) => {
|
||||
return await queryCollection(localStorage.token, doc.collection_name, query, 4).catch(
|
||||
(error) => {
|
||||
console.log(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (relevantContexts) {
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
relevantContexts = relevantContexts.filter((context) => context);
|
||||
|
||||
const contextString = relevantContexts.reduce((a, context, i, arr) => {
|
||||
|
@ -253,7 +252,6 @@
|
|||
|
||||
history.messages[parentId].raContent = RAGTemplate(contextString, query);
|
||||
history.messages[parentId].contexts = relevantContexts;
|
||||
}
|
||||
await tick();
|
||||
processing = '';
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
getTagsById,
|
||||
updateChatById
|
||||
} from '$lib/apis/chats';
|
||||
import { queryVectorDB } from '$lib/apis/rag';
|
||||
import { queryCollection } from '$lib/apis/rag';
|
||||
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
|
||||
|
||||
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
||||
|
@ -246,17 +246,16 @@
|
|||
processing = 'Reading';
|
||||
const query = history.messages[parentId].content;
|
||||
|
||||
let relevantContexts = await queryVectorDB(
|
||||
localStorage.token,
|
||||
docs.map((d) => d.collection_name),
|
||||
query,
|
||||
4
|
||||
).catch((error) => {
|
||||
let relevantContexts = await Promise.all(
|
||||
docs.map(async (doc) => {
|
||||
return await queryCollection(localStorage.token, doc.collection_name, query, 4).catch(
|
||||
(error) => {
|
||||
console.log(error);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (relevantContexts) {
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
relevantContexts = relevantContexts.filter((context) => context);
|
||||
|
||||
const contextString = relevantContexts.reduce((a, context, i, arr) => {
|
||||
|
@ -267,7 +266,6 @@
|
|||
|
||||
history.messages[parentId].raContent = RAGTemplate(contextString, query);
|
||||
history.messages[parentId].contexts = relevantContexts;
|
||||
}
|
||||
await tick();
|
||||
processing = '';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue