Grounding
Basing AI responses on real data or knowledge
Basing AI responses on real data or knowledge
Grounding is a technique that bases an AI model's responses on real data, documents, or reliable knowledge sources. It enables an LLM to generate more accurate and up-to-date answers by referencing external factual information rather than relying solely on its training data.
The need for Grounding stems from the Hallucination problem of LLMs. An LLM generates plausible text based on patterns in its training data, but this does not always match the facts. Grounding is a key strategy for solving this problem.
A representative Grounding technique is RAG (Retrieval-Augmented Generation). It first searches for documents relevant to the user's question and provides them as context so that the LLM generates its answer. Google's Vertex AI Search and Azure's Cognitive Search support this.
In practice, Grounding is essential in chatbots based on internal company documents, customer support systems, and AI assistants in the legal/medical fields. It is a key element for building AI that states the sources of its answers and allows fact-checking.
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.chat_models import ChatOpenAI
from langchain.chains import RetrievalQA
# Grounding을 위한 RAG 파이프라인 구현
def create_grounded_qa_system(documents):
# 1. 문서를 벡터 DB에 저장
embeddings = OpenAIEmbeddings()
vectorstore = Chroma.from_documents(
documents=documents,
embedding=embeddings,
persist_directory="./chroma_db"
)
# 2. Retriever 설정 (상위 3개 관련 문서 검색)
retriever = vectorstore.as_retriever(
search_type="similarity",
search_kwargs={"k": 3}
)
# 3. Grounded QA 체인 생성
llm = ChatOpenAI(model="gpt-4", temperature=0)
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True # 출처 반환
)
return qa_chain
# 사용 예시
qa_system = create_grounded_qa_system(company_docs)
result = qa_system("회사 휴가 정책이 어떻게 되나요?")
print(f"답변: {result['result']}")
print(f"출처: {[doc.metadata['source'] for doc in result['source_documents']]}")
"We need to apply Grounding to the customer inquiry chatbot. If we put the FAQ documents and product manuals into a vector DB and always display the sources, we can prevent incorrect guidance caused by Hallucination."
"The difference between Grounding and Fine-tuning is their purpose. Fine-tuning trains the model on style or domain knowledge, while Grounding injects external information in real time to improve factuality. Using the two together is effective."
"Grounding quality depends on Retriever performance. Semantic Search is far better than simple keyword search, and adding a Reranker lets you retrieve more relevant documents."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
The quality of Grounding depends directly on the quality of the source documents. Outdated or inaccurate documents can instead lead to incorrect answers.
A fallback strategy is needed for when no relevant documents are found. Clearly stating "The information could not be found" is better than Hallucination.
If too many or too long documents are retrieved, they exceed the LLM context window. Design document chunking and summarization strategies together.