Chatbot을 만들면서 가장 귀찮았던건 RAG였다. RAG를 구현하기 위해 VectorDB라는 관리 포인트가 생기며, 임베딩 정책 및 모델 설정, 임베딩할 파일들을 관리하는 컴포넌트까지...RAG 구축 하나로 프로젝트가 복잡해지는 것은 순식간이다.

지난 11월 6일, Google이 Gemini 3, Nano Banana Pro와 함께 Gemini File Search API를 발표했다. Gemini File Search API는 Gemini API에 구축된 RAG 시스템이다. 텍스트 파일 종류라면 대부분 지원하며, File Store를 생성하고 파일을 업로드하는 간단한 절차만으로 검색 기능을 추가할 수 있다.
나는 사내 API 문서를 바탕으로 API에 대한 질의를 할 수 있는 하는 MCP서버를 만들어보기 위해 OpenAPI Spec yaml 문서를 업로드해봤다.
def upload_file(self, file_path: str):
operation = self.client.file_search_stores.upload_to_file_search_store(
file=file_path,
file_search_store_name=self.file_search_store.name, # type: ignore
config={
"display_name": Path(file_path).name,
"mime_type": self.guess_mime_type(file_path),
},
)
# 완료될때까지 operation 업데이트
while not operation.done:
time.sleep(2)
operation = self.client.operations.get(operation)
파일을 청킹하고, 오버랩은 얼마나 할것이며...모델은 뭘 쓸 것인지 구구절절 설정한 것이 하나도 없다.
def search(self, query: str):
prompt = f"""
You are an expert API assistant.
Using the provided OpenAPI specification, find the APIs that are most relevant to the user's query: "{query}"
List the relevant APIs with their Method, Path, and a brief summary.
Explain *why* they are relevant.
"""
response = self.client.models.generate_content(
model=self.model,
contents=prompt,
config=types.GenerateContentConfig(
tools=[
types.Tool(
file_search=types.FileSearch(
file_search_store_names=[self.file_search_store.name] # type: ignore
)
)
]
),
)
return response.text
def search_apis_tool(query: str) -> str:
"""
Search for APIs using Gemini's semantic understanding of the full OpenAPI spec.
Args:
query: The search query (e.g., "How do I buy items?", "Find APIs related to user profile").
Returns:
A natural language answer with relevant API details, grounded in the spec.
"""
try:
return search_api.search(query)
except Exception as e:
return f"Error searching with Gemini: {str(e)[:100]}"
API를 검색하는 도구의 코드도 매우 간단해졌다. (Gemini 의존적이지만)
Gemini API를 그대로 사용하면서, 도구로서 File Search를 넘겨주면 된다. 어떤 파일 스토어를 사용할지 설정할 수 있으며, 메타 데이터를 통한 필터링도 가능하다.
자세한 사용법은 공식 문서를 참고하기를 바란다.
반응형
'프로그래밍 > AI,ML' 카테고리의 다른 글
| 나노바나나로 피규어 만드는 방법 (더 상세한 설정 가능) (0) | 2025.09.02 |
|---|---|
| LLM Tool을 만들다 식겁한 이야기 (1) | 2025.06.21 |
| LLM이 자연스러운 슬랙 메세지를 출력하게 하는 소소한 팁 (0) | 2025.06.21 |
| Agent를 고도화하면서 겪은 문제점들 (0) | 2025.04.09 |
| LangGraph Agent에 장기기억(LTM)추가하기 (0) | 2025.04.03 |