@tool
def run_sql_query(query:str) -> List
Agent 로 sql 쿼리를 할때 프롬프트가 추상적이면 적용이 안되는 경우가 있음 -> iteration 을 주어서 해결이 가능함
랭체인 agent에 verbosa 옵션이 있어서 llm의 호출과정을 이해하는데 도움이 됨
스트링밍 활성화 옵션
llm = ChatOpenAI(
model =
temperature =
streaming=True # 스트리밍 활성화)
streamlit run app.py --server.runOnSave true
파일 저장시 자동으로 적용
vectorstore = PGVector.from_documents(
documents=splits,
embedding=embeddings_model,
collection_name="rag-healthcare",
connection=CONNECTION_STRING,
pre_delete_collection=True
)
pre_delete_collection=True 의 의미는 기존에 동일한 collection 이름(rag-healthcare)이 데이터베이스에 존재하면, 새로 만들기 전에 먼저 삭제하라는 뜻입니다.
def format_docs(docs):
formatted = []
for idx, doc in enumerate(docs, 1):
formatted.append(f"[문서 {idx}]\n{doc.page_content}")
return "\n\n---\n\n".join(formatted)
rag_chain = (
{
"context": retriever | format_docs,
"question": RunnablePassthrough()
}
| prompt_template
| llm
| StrOutputParser()
)
