forked from hangshuo652/aurak
0a9588abb7
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
export interface RagSearchResult {
|
|
content: string;
|
|
fileName: string;
|
|
score: number;
|
|
chunkIndex: number;
|
|
}
|
|
|
|
export interface RagResponse {
|
|
searchResults: RagSearchResult[];
|
|
sources: string[];
|
|
ragPrompt: string;
|
|
hasRelevantContent: boolean;
|
|
}
|
|
|
|
export const ragService = {
|
|
|
|
async search(query: string, settings: any, authToken: string): Promise<RagResponse> {
|
|
try {
|
|
const response = await fetch('/api/knowledge-bases/rag-search', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${authToken}`,
|
|
},
|
|
body: JSON.stringify({ query, settings }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.text();
|
|
console.error('RAG search error:', response.status, errorData);
|
|
throw new Error(`RAG search failed: ${response.status} - ${errorData}`);
|
|
}
|
|
|
|
const result = await response.json();
|
|
return result;
|
|
} catch (error) {
|
|
console.error('RAG service error:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
}; |