FAISS와 Ollama LLM을 활용한 간단한 로컬 푸네 여행 AI 구축 - POC

발행: (2026년 2월 6일 오후 04:40 GMT+9)
8 분 소요
원문: Dev.to

Source: Dev.to

도시 투어나 여행 추천을 위한 자체 로컬 AI 어시스턴트를 만드는 방법이 궁금하셨나요? 이번 개념 증명에서는 임베딩을 위한 FAISS 벡터 데이터베이스와 답변 생성을 위한 Ollama LLM을 사용하여 Pune Grand Tour AI를 구축합니다. Docker도 없고, 클라우드 비용도 없습니다 — 오직 로컬 Python과 임베딩만 사용합니다.

🔹 이 POC의 목적

  • Local AI Assistant – 푸네 관광에 특화된 미니‑ChatGPT.
  • Quick Retrieval – 임베딩을 통해 선별된 데이터셋에 대한 빠른 유사도 검색을 가능하게 합니다.
  • Cost‑efficient – 클라우드 벡터 DB가 없으며, FAISS가 완전히 로컬에서 실행됩니다.
  • Hands‑on AI Exploration – 실용적인 파이프라인을 학습합니다: 임베딩 → 벡터 DB → LLM.

🔹 왜 FAISS인가?

FAISS(Facebook AI Similarity Search)는 고성능 라이브러리로:

  • 벡터 임베딩 저장
  • 빠른 유사도(최근접 이웃) 검색 수행
  • 클라우드 인프라 없이 로컬에서 실행

핵심 포인트: 모든 Pune 데이터가 메모리에 여유롭게 들어가므로 FAISS는 번개처럼 빠른 검색을 제공합니다.

🔹 데이터셋

우리는 푸네의 다음 항목들을 포함하는 간단한 텍스트 파일(pune_places_chunks.txt)을 사용합니다:

  • 역사적인 요새
  • 기념물
  • 박물관
  • 관광지

각 행 또는 청크는 하나의 문서를 나타냅니다. 예시:

[PLACE] Shaniwar Wada
Shaniwar Wada is a historic fort located in Pune, built in 1732 by Peshwa Bajirao I.
It served as the administrative center of the Maratha Empire.

[PLACE] Aga Khan Palace
The Aga Khan Palace is known for its association with Mahatma Gandhi and history.

🔹 Step 1 – 임베딩 및 FAISS 벡터 스토어 생성

File: ingest.py

from langchain_community.document_loaders import TextLoader
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_community.vectorstores import FAISS

# 1️⃣ Load processed Pune data
loader = TextLoader("../data/processed/pune_places_chunks.txt")
documents = loader.load()

# 2️⃣ Create embeddings
embeddings = HuggingFaceEmbeddings(
    model_name="sentence-transformers/all-MiniLM-L6-v2"
)

# 3️⃣ Build FAISS vector store
vectorstore = FAISS.from_documents(documents, embeddings)

# 4️⃣ Persist the DB locally
vectorstore.save_local("../embeddings/pune_faiss")

print("Pune embeddings created successfully")

실행:

python ingest.py

예상 출력

Pune embeddings created successfully

설명

  • TextLoader는 텍스트 청크를 읽습니다.
  • HuggingFaceEmbeddings는 각 청크를 벡터로 변환합니다.
  • FAISS.from_documents는 검색 가능한 벡터 스토어를 구축합니다.
  • save_local는 나중에 사용할 수 있도록 FAISS 인덱스를 로컬에 저장합니다.

Source:

🔹 단계 2 – Ollama LLM으로 FAISS 쿼리

파일: chat.py

from langchain_community.vectorstores import FAISS
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_ollama import OllamaLLM

# 1️⃣ Load embeddings
embeddings = HuggingFaceEmbeddings(
    model_name="sentence-transformers/all-MiniLM-L6-v2"
)
print("Embeddings loaded")

# 2️⃣ Load FAISS DB (allow pickle deserialization)
vectordb = FAISS.load_local(
    "../embeddings/pune_faiss",
    embeddings,
    allow_dangerous_deserialization=True
)
print("FAISS Vector DB loaded")

# 3️⃣ Ask a question
question = "Tell me famous places to visit in Pune"
docs = vectordb.similarity_search(question, k=3)

if not docs:
    print("No documents retrieved. Check embeddings folder.")
    exit(1)

context = "\n".join([d.page_content for d in docs])
print(f"Retrieved docs count: {len(docs)}")
print("Context preview (first 300 chars):")
print(context[:300])

# 4️⃣ Initialise Ollama LLM
llm = OllamaLLM(model="llama3")
print("Ollama LLM loaded")

# 5️⃣ Build prompt
prompt = f"""
You are a Pune travel guide AI.
Answer using only the context below.

Context:
{context}

Question:
{question}
"""

# 6️⃣ Generate response
response = llm.invoke(prompt)

print("\nPune AI says:\n")
print(response)

실행:

python chat.py

샘플 출력

Embeddings loaded
FAISS Vector DB loaded
Retrieved docs count: 3
Context preview (first 300 chars):
[PLACE] Shaniwar Wada
Shaniwar Wada is a historic fort located in Pune, built in 1732...
Ollama LLM loaded

Pune AI says:

Pune is famous for Shaniwar Wada, Sinhagad Fort, Aga Khan Palace, and Dagdusheth Ganpati Temple.

설명

  • similarity_search는 가장 관련성이 높은 상위 k개의 문서를 가져옵니다.
  • 가져온 컨텍스트를 연결한 뒤 Ollama LLM에 전달합니다.
  • LLM은 제공된 컨텍스트만을 기반으로 인간과 같은 답변을 생성합니다.

Source:

🔹 Step 3 – Make It Interactive with Streamlit

File: app.py

import streamlit as st
from langchain_community.vectorstores import FAISS
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_ollama import OllamaLLM

st.title("Pune Grand Tour AI")
st.write("Ask about Pune's forts, monuments, and travel tips!")

@st.cache_resource
def load_vectorstore():
    embeddings = HuggingFaceEmbeddings(
        model_name="sentence-transformers/all-MiniLM-L6-v2"
    )
    return FAISS.load_local(
        "../embeddings/pune_faiss",
        embeddings,
        allow_dangerous_deserialization=True,
    )

@st.cache_resource
def load_llm():
    return OllamaLLM(model="llama3")

vectordb = load_vectorstore()
llm = load_llm()

question = st.text_input("Ask a question about Pune:")

if question:
    docs = vectordb.similarity_search(question, k=3)
    if not docs:
        st.warning("No documents found!")
    else:
        context = "\n".join([d.page_content for d in docs])
        prompt = f"""
You are a Pune travel guide AI.

Context:
{context}

Question:
{question}
"""
        response = llm.invoke(prompt)

        st.subheader("Retrieved Context")
        st.text(context[:500] + ("..." if len(context) > 500 else ""))

        st.subheader("AI Answer")
        st.write(response)

앱 실행:

streamlit run app.py

이제 사용자가 Pune와 관련된 질문을 입력하면 로컬 임베딩과 Ollama LLM을 활용해 답변을 제공하는 완전한 인터랙티브 웹 UI가 준비되었습니다.

🎉 이제 모두 완료되었습니다!

Pune 관광을 위한 완전한 로컬 AI 어시스턴트를 구축했습니다:

  1. Ingest 원시 텍스트 → 임베딩 → FAISS 인덱스.
  2. Retrieve 유사도 검색으로 관련 청크를 찾기.
  3. Generate Ollama LLM으로 답변 생성.
  4. Interact Streamlit 웹 앱을 통해 상호작용.

이 모든 과정이 여러분의 머신에서 실행됩니다—클라우드 비용도, Docker도 없이, 오직 Python만으로. 즐거운 여행 되세요!

애플리케이션 실행

pip install streamlit
streamlit run app.py

결과

브라우저 UI가 열리며 푸네와 관련된 어떤 질문이든 할 수 있고, AI가 인터랙티브하게 응답합니다.

🔹 이 POC의 주요 장점

  • 완전 로컬 – 클라우드나 Docker 의존 없음.
  • 빠른 검색 – FAISS가 즉시 유사도 검색을 제공합니다.
  • 컨텍스트 인식 AI – Ollama LLM이 정제된 푸네 지식을 기반으로 답변합니다.
  • 확장 가능 – 더 많은 문서, 이미지 또는 여행 팁을 추가할 수 있습니다.
  • 인터랙티브 UI – Streamlit을 통해 누구나 AI를 쉽게 사용할 수 있습니다.

🔹 일반적인 문제 및 해결 방법

Common Issues & Fixes

🔹 사용 사례

  • 관광 앱을 위한 로컬 도시 가이드 AI
  • 지리/역사 수업을 위한 교육 보조 AI
  • 어떤 정제된 데이터셋이든 사용할 수 있는 개인 지식 보조 AI
  • RAG(검색 강화 생성) 프로젝트를 위한 프로토타입

🔹 결론

FAISS + Ollama LLM + Streamlit을 사용하면 클라우드 서비스나 Docker에 의존하지 않고 빠르고 로컬이며 컨텍스트 인식 AI 어시스턴트를 구축할 수 있습니다. 이 푸네 AI POC는 특화된 지식 베이스가 정확하고 상황에 맞는 답변을 제공하는 챗봇을 어떻게 구동할 수 있는지를 보여줍니다.

Back to Blog

관련 글

더 보기 »

시계열 예측: 전통적 방법과 ML 접근법

시계열 예측: 전통적 접근법과 ML 접근법을 활용한 신뢰할 수 있는 예측 시스템 구축 상상해 보세요: 블랙 프라이데이 기간에 귀하의 e‑commerce 플랫폼이 갑자기 다운되는 상황을.