ragService.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. export interface RagSearchResult {
  2. content: string;
  3. fileName: string;
  4. score: number;
  5. chunkIndex: number;
  6. }
  7. export interface RagResponse {
  8. searchResults: RagSearchResult[];
  9. sources: string[];
  10. ragPrompt: string;
  11. hasRelevantContent: boolean;
  12. }
  13. export const ragService = {
  14. async search(query: string, settings: any, authToken: string): Promise<RagResponse> {
  15. try {
  16. const response = await fetch('/api/knowledge-bases/rag-search', {
  17. method: 'POST',
  18. headers: {
  19. 'Content-Type': 'application/json',
  20. 'Authorization': `Bearer ${authToken}`,
  21. },
  22. body: JSON.stringify({ query, settings }),
  23. });
  24. if (!response.ok) {
  25. const errorData = await response.text();
  26. console.error('RAG search error:', response.status, errorData);
  27. throw new Error(`RAG search failed: ${response.status} - ${errorData}`);
  28. }
  29. const result = await response.json();
  30. return result;
  31. } catch (error) {
  32. console.error('RAG service error:', error);
  33. throw error;
  34. }
  35. },
  36. };