ragService.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export interface RagSearchResult {
  2. content: string;
  3. fileName: string;
  4. score: number;
  5. chunkIndex: number;
  6. pageNumber?: number; // 追加
  7. fileId?: string; // 追加
  8. }
  9. export interface RagResponse {
  10. searchResults: RagSearchResult[];
  11. sources: string[];
  12. ragPrompt: string;
  13. hasRelevantContent: boolean;
  14. }
  15. export const ragService = {
  16. /**
  17. * RAG サービス - RAG 検索結果の直接取得を担当(チャットインターフェースではなく、デバッグや検証用)
  18. */
  19. async search(query: string, settings: any, authToken: string): Promise<RagResponse> {
  20. try {
  21. const response = await fetch('/api/knowledge-bases/rag-search', {
  22. method: 'POST',
  23. headers: {
  24. 'Content-Type': 'application/json',
  25. 'Authorization': `Bearer ${authToken}`,
  26. },
  27. body: JSON.stringify({ query, settings }),
  28. });
  29. if (!response.ok) {
  30. const errorData = await response.text();
  31. console.error('RAG search error:', response.status, errorData);
  32. throw new Error(`RAG search failed: ${response.status} - ${errorData}`);
  33. }
  34. const result = await response.json();
  35. return result;
  36. } catch (error) {
  37. console.error('RAG service error:', error);
  38. throw error;
  39. }
  40. },
  41. };