30. Test RAG from CSV.ipynb

# Load the CSV file as documents
loader = CSVLoader(file_path='busan_restaurants.csv', encoding='utf-8-sig')
docs = loader.load()

# Initialize OpenAI embeddings (or another embedding model)
embeddings = OpenAIEmbeddings(openai_api_key=OPEN_API_KEY)

# Use FAISS as the vector store for similarity search
vectorstore = FAISS.from_documents(docs, embeddings)

# Initialize the OpenAI LLM (or use another LLM like GPT-4)
llm = OpenAI(openai_api_key=OPEN_API_KEY)

# Set up the RetrievalQA chain
qa_chain = RetrievalQA.from_chain_type(
    llm=llm,
    chain_type="stuff",  # You can use 'map_reduce' or others if needed
    retriever=vectorstore.as_retriever(),
)

# Query the system with a question related to the CSV data
query = "만드리곤드레밥에서는 무슨 음식을 파나요?"
response = qa_chain.run(query)

# Output the response
print(response)

image.png