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,28 +232,26 @@ | ||||||
| 			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 | 							console.log(error); | ||||||
| 			).catch((error) => { | 							return null; | ||||||
| 				console.log(error); | 						} | ||||||
| 				return null; | 					); | ||||||
| 			}); | 				}) | ||||||
|  | 			); | ||||||
|  | 			relevantContexts = relevantContexts.filter((context) => context); | ||||||
| 
 | 
 | ||||||
| 			if (relevantContexts) { | 			const contextString = relevantContexts.reduce((a, context, i, arr) => { | ||||||
| 				relevantContexts = relevantContexts.filter((context) => context); | 				return `${a}${context.documents.join(' ')}\n`; | ||||||
|  | 			}, ''); | ||||||
| 
 | 
 | ||||||
| 				const contextString = relevantContexts.reduce((a, context, i, arr) => { | 			console.log(contextString); | ||||||
| 					return `${a}${context.documents.join(' ')}\n`; |  | ||||||
| 				}, ''); |  | ||||||
| 
 | 
 | ||||||
| 				console.log(contextString); | 			history.messages[parentId].raContent = RAGTemplate(contextString, query); | ||||||
| 
 | 			history.messages[parentId].contexts = relevantContexts; | ||||||
| 				history.messages[parentId].raContent = RAGTemplate(contextString, query); |  | ||||||
| 				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,28 +246,26 @@ | ||||||
| 			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 | 							console.log(error); | ||||||
| 			).catch((error) => { | 							return null; | ||||||
| 				console.log(error); | 						} | ||||||
| 				return null; | 					); | ||||||
| 			}); | 				}) | ||||||
|  | 			); | ||||||
|  | 			relevantContexts = relevantContexts.filter((context) => context); | ||||||
| 
 | 
 | ||||||
| 			if (relevantContexts) { | 			const contextString = relevantContexts.reduce((a, context, i, arr) => { | ||||||
| 				relevantContexts = relevantContexts.filter((context) => context); | 				return `${a}${context.documents.join(' ')}\n`; | ||||||
|  | 			}, ''); | ||||||
| 
 | 
 | ||||||
| 				const contextString = relevantContexts.reduce((a, context, i, arr) => { | 			console.log(contextString); | ||||||
| 					return `${a}${context.documents.join(' ')}\n`; |  | ||||||
| 				}, ''); |  | ||||||
| 
 | 
 | ||||||
| 				console.log(contextString); | 			history.messages[parentId].raContent = RAGTemplate(contextString, query); | ||||||
| 
 | 			history.messages[parentId].contexts = relevantContexts; | ||||||
| 				history.messages[parentId].raContent = RAGTemplate(contextString, query); |  | ||||||
| 				history.messages[parentId].contexts = relevantContexts; |  | ||||||
| 			} |  | ||||||
| 			await tick(); | 			await tick(); | ||||||
| 			processing = ''; | 			processing = ''; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek