forked from open-webui/open-webui
		
	feat: add rag top k value setting
This commit is contained in:
		
							parent
							
								
									9694c6569f
								
							
						
					
					
						commit
						47a05a47b4
					
				
					 5 changed files with 123 additions and 38 deletions
				
			
		|  | @ -85,17 +85,49 @@ export const getRAGTemplate = async (token: string) => { | |||
| 	return res?.template ?? ''; | ||||
| }; | ||||
| 
 | ||||
| export const updateRAGTemplate = async (token: string, template: string) => { | ||||
| export const getQuerySettings = async (token: string) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
| 	const res = await fetch(`${RAG_API_BASE_URL}/template/update`, { | ||||
| 	const res = await fetch(`${RAG_API_BASE_URL}/query/settings`, { | ||||
| 		method: 'GET', | ||||
| 		headers: { | ||||
| 			'Content-Type': 'application/json', | ||||
| 			Authorization: `Bearer ${token}` | ||||
| 		} | ||||
| 	}) | ||||
| 		.then(async (res) => { | ||||
| 			if (!res.ok) throw await res.json(); | ||||
| 			return res.json(); | ||||
| 		}) | ||||
| 		.catch((err) => { | ||||
| 			console.log(err); | ||||
| 			error = err.detail; | ||||
| 			return null; | ||||
| 		}); | ||||
| 
 | ||||
| 	if (error) { | ||||
| 		throw error; | ||||
| 	} | ||||
| 
 | ||||
| 	return res; | ||||
| }; | ||||
| 
 | ||||
| type QuerySettings = { | ||||
| 	k: number | null; | ||||
| 	template: string | null; | ||||
| }; | ||||
| 
 | ||||
| export const updateQuerySettings = async (token: string, settings: QuerySettings) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
| 	const res = await fetch(`${RAG_API_BASE_URL}/query/settings/update`, { | ||||
| 		method: 'POST', | ||||
| 		headers: { | ||||
| 			'Content-Type': 'application/json', | ||||
| 			Authorization: `Bearer ${token}` | ||||
| 		}, | ||||
| 		body: JSON.stringify({ | ||||
| 			template: template | ||||
| 			...settings | ||||
| 		}) | ||||
| 	}) | ||||
| 		.then(async (res) => { | ||||
|  | @ -183,7 +215,7 @@ export const queryDoc = async ( | |||
| 	token: string, | ||||
| 	collection_name: string, | ||||
| 	query: string, | ||||
| 	k: number | ||||
| 	k: number | null = null | ||||
| ) => { | ||||
| 	let error = null; | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,10 +2,10 @@ | |||
| 	import { getDocs } from '$lib/apis/documents'; | ||||
| 	import { | ||||
| 		getChunkParams, | ||||
| 		getRAGTemplate, | ||||
| 		getQuerySettings, | ||||
| 		scanDocs, | ||||
| 		updateChunkParams, | ||||
| 		updateRAGTemplate | ||||
| 		updateQuerySettings | ||||
| 	} from '$lib/apis/rag'; | ||||
| 	import { documents } from '$lib/stores'; | ||||
| 	import { onMount } from 'svelte'; | ||||
|  | @ -18,7 +18,10 @@ | |||
| 	let chunkSize = 0; | ||||
| 	let chunkOverlap = 0; | ||||
| 
 | ||||
| 	let template = ''; | ||||
| 	let querySettings = { | ||||
| 		template: '', | ||||
| 		k: 4 | ||||
| 	}; | ||||
| 
 | ||||
| 	const scanHandler = async () => { | ||||
| 		loading = true; | ||||
|  | @ -33,7 +36,7 @@ | |||
| 
 | ||||
| 	const submitHandler = async () => { | ||||
| 		const res = await updateChunkParams(localStorage.token, chunkSize, chunkOverlap); | ||||
| 		await updateRAGTemplate(localStorage.token, template); | ||||
| 		querySettings = await updateQuerySettings(localStorage.token, querySettings); | ||||
| 	}; | ||||
| 
 | ||||
| 	onMount(async () => { | ||||
|  | @ -44,7 +47,7 @@ | |||
| 			chunkOverlap = res.chunk_overlap; | ||||
| 		} | ||||
| 
 | ||||
| 		template = await getRAGTemplate(localStorage.token); | ||||
| 		querySettings = await getQuerySettings(localStorage.token); | ||||
| 	}); | ||||
| </script> | ||||
| 
 | ||||
|  | @ -156,10 +159,44 @@ | |||
| 				</div> | ||||
| 			</div> | ||||
| 
 | ||||
| 			<div class=" text-sm font-medium">Query Params</div> | ||||
| 
 | ||||
| 			<div class=" flex"> | ||||
| 				<div class="  flex w-full justify-between"> | ||||
| 					<div class="self-center text-xs font-medium flex-1">Top K</div> | ||||
| 
 | ||||
| 					<div class="self-center p-3"> | ||||
| 						<input | ||||
| 							class=" w-full rounded py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none border border-gray-100 dark:border-gray-600" | ||||
| 							type="number" | ||||
| 							placeholder="Enter Top K" | ||||
| 							bind:value={querySettings.k} | ||||
| 							autocomplete="off" | ||||
| 							min="0" | ||||
| 						/> | ||||
| 					</div> | ||||
| 				</div> | ||||
| 
 | ||||
| 				<!-- <div class="flex w-full"> | ||||
| 					<div class=" self-center text-xs font-medium min-w-fit">Chunk Overlap</div> | ||||
| 
 | ||||
| 					<div class="self-center p-3"> | ||||
| 						<input | ||||
| 							class="w-full rounded py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none border border-gray-100 dark:border-gray-600" | ||||
| 							type="number" | ||||
| 							placeholder="Enter Chunk Overlap" | ||||
| 							bind:value={chunkOverlap} | ||||
| 							autocomplete="off" | ||||
| 							min="0" | ||||
| 						/> | ||||
| 					</div> | ||||
| 				</div> --> | ||||
| 			</div> | ||||
| 
 | ||||
| 			<div> | ||||
| 				<div class=" mb-2.5 text-sm font-medium">RAG Template</div> | ||||
| 				<textarea | ||||
| 					bind:value={template} | ||||
| 					bind:value={querySettings.template} | ||||
| 					class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none" | ||||
| 					rows="4" | ||||
| 				/> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek