| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 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;
- }
- },
- };
|