woongmin commited on
Commit
aea0bb5
·
1 Parent(s): 0a7fe27

[Delta-02] get_embedding, save_embedding 구현 및 업로드 파이프라인 연결

Browse files
Files changed (3) hide show
  1. app/embedding_utils.py +1 -6
  2. app/main.py +9 -1
  3. app/supabase_utils.py +9 -1
app/embedding_utils.py CHANGED
@@ -124,9 +124,4 @@ def get_embedding(text: str) -> List[float]:
124
  Returns:
125
  List[float]: 임베딩 벡터
126
  """
127
- # ---------------------------------------------------------
128
- # [Day 2] 과제: 여기에 임베딩 생성 로직을 작성하세요.
129
- # 기본: Ollama 로컬 API 호출
130
- # 선택: OpenAI API 호출 (PROVIDER=openai일 때)
131
- # ---------------------------------------------------------
132
- pass
 
124
  Returns:
125
  List[float]: 임베딩 벡터
126
  """
127
+ return _ollama_embed(text)
 
 
 
 
 
app/main.py CHANGED
@@ -87,10 +87,18 @@ async def upload_document(file: UploadFile = File(...)):
87
  # 2. 텍스트 추출
88
  text = extract_text_from_pdf(file_path)
89
 
 
 
 
 
 
 
 
 
90
  return {
91
  "message": "문서 처리가 완료되었습니다.",
92
  "document_id": document_id,
93
- # "chunks_count": ...
94
  }
95
 
96
  except Exception as e:
 
87
  # 2. 텍스트 추출
88
  text = extract_text_from_pdf(file_path)
89
 
90
+ # 3. 청크 분할
91
+ chunks = split_text(text)
92
+
93
+ # 4. 임베딩 및 저장
94
+ for i, chunk in enumerate(chunks):
95
+ embedding = get_embedding(chunk)
96
+ save_embedding(document_id, chunk, embedding, i)
97
+
98
  return {
99
  "message": "문서 처리가 완료되었습니다.",
100
  "document_id": document_id,
101
+ "chunks_count": len(chunks),
102
  }
103
 
104
  except Exception as e:
app/supabase_utils.py CHANGED
@@ -36,7 +36,15 @@ def save_embedding(
36
  # ---------------------------------------------------------
37
  # [Day 2] 과제: 여기에 DB 저장 로직을 작성하세요.
38
  # ---------------------------------------------------------
39
- pass
 
 
 
 
 
 
 
 
40
 
41
 
42
  def search_similar_embeddings(
 
36
  # ---------------------------------------------------------
37
  # [Day 2] 과제: 여기에 DB 저장 로직을 작성하세요.
38
  # ---------------------------------------------------------
39
+ data = {
40
+ "document_id": document_id,
41
+ "content": chunk,
42
+ "embedding": embedding,
43
+ "chunk_index": chunk_index,
44
+ "metadata": {},
45
+ }
46
+ result = supabase.table("document_chunks").insert(data).execute()
47
+ return result.data
48
 
49
 
50
  def search_similar_embeddings(