0Pricing
LLM Apps in Production (RAG + Vector DB + Caching) · レッスン

自己クエリと引用

自然言語をメタデータフィルターに変換する自己クエリRetrieverと、出典を示してユーザーが回答を信頼・検証できる仕組みで、RAGをさらに発展させます。

「自己クエリと引用」はCoddyKit上の無料LLM Apps in Production (RAG + Vector DB + Caching)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLLM Apps in Production (RAG + Vector DB + Caching)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 LLM Apps in Production (RAG + Vector DB + Caching)コースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

When Questions Carry Filters

Users ask things like give me 2023 reports about pricing. That sentence contains a filter (year 2023) and a semantic query (pricing).

A self-querying retriever automatically separates the two.

How Self-Querying Works

An LLM reads the question and emits a structured query: the semantic search string plus a metadata filter. The retriever then applies both to the vector store.

Describing Your Metadata

You tell the retriever what fields exist so it knows what it can filter on.

from langchain.chains.query_constructor.schema import AttributeInfo

fields = [
    AttributeInfo(name='year', description='Publication year', type='integer'),
    AttributeInfo(name='topic', description='Document topic', type='string')
]

Building the Retriever

Combine the LLM, the store, a content description, and the field info into a self-query retriever.

from langchain.retrievers.self_query.base import SelfQueryRetriever

retriever = SelfQueryRetriever.from_llm(
    llm, vectorstore,
    'Company reports', fields
)

Seeing It in Action

Now a natural-language question is split into a filter and a search automatically — no manual filter code.

docs = retriever.invoke(
    'pricing reports from 2023'
)

Why Citations Matter

In production, users must be able to verify answers. Unsourced answers are hard to trust and hide hallucinations. Citations link each claim back to its document.

Carrying Source Metadata

Citations rely on each chunk storing where it came from — file name, page, or URL — in its metadata. Set this at load time.

doc.metadata['source'] = 'policy.pdf#p3'

Prompting for Citations

Number the context chunks and ask the model to cite the numbers it used. This is simple and reliable.

ctx = '\n'.join(
    f'[{i}] {d.page_content}'
    for i, d in enumerate(docs)
)
# 'Cite sources like [1] after each claim.'

Mapping Numbers to Sources

After generation, map the cited numbers back to real source metadata so the UI can show clickable references.

sources = {i: d.metadata['source']
           for i, d in enumerate(docs)}

Verifying Citations

Models sometimes cite wrong or nonexistent sources. A safety check confirms each cited chunk actually supports the claim, flagging unsupported statements.

Putting It Together

Self-querying gets the right documents using filters in the question; citations make the resulting answer transparent. Together they raise both precision and trust in advanced RAG.

Quick Check

Test your advanced RAG knowledge.

Recap

You learned two advanced RAG techniques:

  • Self-querying turns natural language into metadata filters plus a semantic query
  • Describe your fields so the LLM knows what to filter
  • Citations link claims to sources for trust
  • Carry source metadata, prompt for citations, and verify them

Filtering and citing together make RAG both precise and trustworthy.

よくある質問

「自己クエリと引用」レッスンは無料ですか?

はい。「自己クエリと引用」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、LLM Apps in Production (RAG + Vector DB + Caching)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 LLM Apps in Production (RAG + Vector DB + Caching)コースには全4レッスンが含まれています。

「自己クエリと引用」で何を学びますか?

自然言語をメタデータフィルターに変換する自己クエリRetrieverと、出典を示してユーザーが回答を信頼・検証できる仕組みで、RAGをさらに発展させます。 ブラウザで直接実行するハンズオンコードでLLM Apps in Production (RAG + Vector DB + Caching)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

LLM Apps in Production (RAG + Vector DB + Caching)を始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLLM Apps in Production (RAG + Vector DB + Caching)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「自己クエリと引用」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLLM Apps in Production (RAG + Vector DB + Caching)レッスンでコードを書いて実行できますか?

はい。すべてのLLM Apps in Production (RAG + Vector DB + Caching)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. クエリの書き換えと再ランキング
  2. 多段階RAGとエージェント型RAGのパターン
  3. 複雑なドキュメント構造への対応
  4. 自己クエリと引用
← LLM Apps in Production (RAG + Vector DB + Caching)に戻る