ragService.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /**
  15. * RAG サービス - RAG 検索結果の直接取得を担当(チャットインターフェースではなく、デバッグや検証用)
  16. */
  17. async search(query: string, settings: any, authToken: string): Promise<RagResponse> {
  18. try {
  19. const response = await fetch('/api/knowledge-bases/rag-search', {
  20. method: 'POST',
  21. headers: {
  22. 'Content-Type': 'application/json',
  23. 'Authorization': `Bearer ${authToken}`,
  24. },
  25. body: JSON.stringify({ query, settings }),
  26. });
  27. if (!response.ok) {
  28. const errorData = await response.text();
  29. console.error('RAG search error:', response.status, errorData);
  30. throw new Error(`RAG search failed: ${response.status} - ${errorData}`);
  31. }
  32. const result = await response.json();
  33. return result;
  34. } catch (error) {
  35. console.error('RAG service error:', error);
  36. throw error;
  37. }
  38. },
  39. };