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 (
|
export const queryVectorDB = async (
|
||||||
token: string,
|
token: string,
|
||||||
collection_names: string[],
|
collection_name: string,
|
||||||
query: string,
|
query: string,
|
||||||
k: number
|
k: number
|
||||||
) => {
|
) => {
|
||||||
let error = null;
|
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',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
|
@ -80,7 +80,7 @@ export const queryVectorDB = async (
|
||||||
authorization: `Bearer ${token}`
|
authorization: `Bearer ${token}`
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
collection_names: collection_names,
|
collection_name: collection_name,
|
||||||
query: query,
|
query: query,
|
||||||
k: k
|
k: k
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
getTagsById,
|
getTagsById,
|
||||||
updateChatById
|
updateChatById
|
||||||
} from '$lib/apis/chats';
|
} from '$lib/apis/chats';
|
||||||
import { queryVectorDB } from '$lib/apis/rag';
|
import { queryCollection } from '$lib/apis/rag';
|
||||||
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
|
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
|
||||||
|
|
||||||
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
||||||
|
@ -232,17 +232,16 @@
|
||||||
processing = 'Reading';
|
processing = 'Reading';
|
||||||
const query = history.messages[parentId].content;
|
const query = history.messages[parentId].content;
|
||||||
|
|
||||||
let relevantContexts = await queryVectorDB(
|
let relevantContexts = await Promise.all(
|
||||||
localStorage.token,
|
docs.map(async (doc) => {
|
||||||
docs.map((d) => d.collection_name),
|
return await queryCollection(localStorage.token, doc.collection_name, query, 4).catch(
|
||||||
query,
|
(error) => {
|
||||||
4
|
|
||||||
).catch((error) => {
|
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return null;
|
return null;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
if (relevantContexts) {
|
})
|
||||||
|
);
|
||||||
relevantContexts = relevantContexts.filter((context) => context);
|
relevantContexts = relevantContexts.filter((context) => context);
|
||||||
|
|
||||||
const contextString = relevantContexts.reduce((a, context, i, arr) => {
|
const contextString = relevantContexts.reduce((a, context, i, arr) => {
|
||||||
|
@ -253,7 +252,6 @@
|
||||||
|
|
||||||
history.messages[parentId].raContent = RAGTemplate(contextString, query);
|
history.messages[parentId].raContent = RAGTemplate(contextString, query);
|
||||||
history.messages[parentId].contexts = relevantContexts;
|
history.messages[parentId].contexts = relevantContexts;
|
||||||
}
|
|
||||||
await tick();
|
await tick();
|
||||||
processing = '';
|
processing = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
getTagsById,
|
getTagsById,
|
||||||
updateChatById
|
updateChatById
|
||||||
} from '$lib/apis/chats';
|
} from '$lib/apis/chats';
|
||||||
import { queryVectorDB } from '$lib/apis/rag';
|
import { queryCollection } from '$lib/apis/rag';
|
||||||
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
|
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
|
||||||
|
|
||||||
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
||||||
|
@ -246,17 +246,16 @@
|
||||||
processing = 'Reading';
|
processing = 'Reading';
|
||||||
const query = history.messages[parentId].content;
|
const query = history.messages[parentId].content;
|
||||||
|
|
||||||
let relevantContexts = await queryVectorDB(
|
let relevantContexts = await Promise.all(
|
||||||
localStorage.token,
|
docs.map(async (doc) => {
|
||||||
docs.map((d) => d.collection_name),
|
return await queryCollection(localStorage.token, doc.collection_name, query, 4).catch(
|
||||||
query,
|
(error) => {
|
||||||
4
|
|
||||||
).catch((error) => {
|
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return null;
|
return null;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
if (relevantContexts) {
|
})
|
||||||
|
);
|
||||||
relevantContexts = relevantContexts.filter((context) => context);
|
relevantContexts = relevantContexts.filter((context) => context);
|
||||||
|
|
||||||
const contextString = relevantContexts.reduce((a, context, i, arr) => {
|
const contextString = relevantContexts.reduce((a, context, i, arr) => {
|
||||||
|
@ -267,7 +266,6 @@
|
||||||
|
|
||||||
history.messages[parentId].raContent = RAGTemplate(contextString, query);
|
history.messages[parentId].raContent = RAGTemplate(contextString, query);
|
||||||
history.messages[parentId].contexts = relevantContexts;
|
history.messages[parentId].contexts = relevantContexts;
|
||||||
}
|
|
||||||
await tick();
|
await tick();
|
||||||
processing = '';
|
processing = '';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue