AI Agent Development and Interview Guide: 03-Production-Grade RAG and Knowledge Engineering

Deconstructs production-grade RAG pipelines, including chunking strategies, hybrid search (BM25 + vector), re-ranking, multi-tenant ACL access control, and retrieval metrics.

Contents30 sections

Chapter 3: Production-Grade RAG and Knowledge Engineering

technical system component,RAG、knowledge basestechnical system component。technical system component“technical system component PDF technical system component”,technical system component:technical system component、technical system component、technical system component、technical system component。

1. RAG technical system component

RAG(Retrieval-Augmented Generation)technical system component,technical system component。technical system component:

  • technical system component;
  • technical system component、technical system component;
  • technical system component;
  • technical system component。

RAG technical system component:

  • technical system component;
  • technical system component;
  • technical system component;
  • technical system component;
  • technical system component、technical system component。

🔥 P0 High-Frequency Must-Know: RAG technical system component Fine-tuning technical system component?
RAG technical system component,technical system component、technical system component;technical system component,technical system component,technical system component。technical system component RAG,technical system component/technical system component/technical system component。

2. technical system component RAG technical system component

TEXT
technical system component
  -> technical system component
  -> technical system component
  -> technical system component
  -> Embedding / technical system component
  -> technical system component
  -> technical system component
  -> Rerank
  -> technical system component
  -> technical system component
  -> technical system component

technical system component。technical system componentvector databases,technical system component。

3. technical system component:technical system component,technical system component

PDF technical system component。technical system component:

  • technical system component;
  • technical system component;
  • technical system component;
  • technical system component;
  • technical system component;
  • code、technical system component;
  • technical system component。

technical system component:

PYTHON
from pydantic import BaseModel


class ParsedBlock(BaseModel):
    document_id: str
    document_version: str
    block_id: str
    block_type: str       # paragraph/table/code/title
    text: str
    page: int | None
    heading_path: list[str]
    source_uri: str
    updated_at: str
    access_tags: list[str]

source_uri、technical system component;access_tags technical system component;document_version technical system component。

technical system component

technical system component。technical system component:

PYTHON
import hashlib


def content_hash(text: str) -> str:
    normalized = " ".join(text.split())
    return hashlib.sha256(normalized.encode("utf-8")).hexdigest()

technical system component Embedding。technical system component,technical system component。

4. Chunking:technical system component

Chunk technical system component:technical system component、technical system component。
Chunk technical system component:technical system component、technical system component、Rerank technical system component。

technical system component:

technical system componenttechnical system componenttechnical system componenttechnical system component
technical system component Token + overlaptechnical system component、technical system componenttechnical system componenttechnical system component
technical system component/technical system componenttechnical system componenttechnical system componenttechnical system component、technical system component、technical system component
semantic chunkingtechnical system componenttechnical system component,technical system componenttechnical system component
Parent-Childtechnical system component、technical system componenttechnical system componenttechnical system component
technical system componenttechnical system componenttechnical system componentFAQ、technical system component、technical system component、technical system component

technical system component:

PYTHON
from dataclasses import dataclass


@dataclass
class Chunk:
    chunk_id: str
    text: str
    heading_path: tuple[str, ...]
    source_uri: str


def chunk_sections(sections, max_chars: int = 1200) -> list[Chunk]:
    chunks = []
    for section in sections:
        paragraphs = section.paragraphs
        buffer = []
        length = 0

        for paragraph in paragraphs:
            if buffer and length + len(paragraph) > max_chars:
                index = len(chunks)
                chunks.append(Chunk(
                    chunk_id=f"{section.id}:{index}",
                    text="\n".join(buffer),
                    heading_path=tuple(section.heading_path),
                    source_uri=section.source_uri,
                ))
                buffer = []
                length = 0

            buffer.append(paragraph)
            length += len(paragraph)

        if buffer:
            index = len(chunks)
            chunks.append(Chunk(
                chunk_id=f"{section.id}:{index}",
                text="\n".join(buffer),
                heading_path=tuple(section.heading_path),
                source_uri=section.source_uri,
            ))
    return chunks

technical system component,technical system component Tokenizer technical system component,technical system component、technical system component。

🔥 P0 High-Frequency Must-Know: Chunk technical system component?
technical system component。technical system component,technical system component,technical system component Chunk/overlap technical system component Recall@k、technical system component、technical system component。technical system component,technical system component。

5. Embedding technical system component

Embedding technical system component,technical system component。technical system component、technical system component。technical system component。

technical system component:

  • technical system component;
  • technical system component;
  • technical system component;
  • technical system component、technical system component;
  • technical system component;
  • technical system component。

technical system component Embedding。technical system component—technical system component。

Dense technical system component、technical system component;BM25 technical system component Sparse technical system component、technical system component、technical system component。hybrid searchtechnical system component。

Pinecone technical system component:technical system component,technical system component;Hybrid Search technical system component。technical system component Hybrid search。

RRF technical system component

Reciprocal Rank Fusion technical system component:

TEXT
RRF(d) = Σ 1 / (k + rank_i(d))

technical system component:

PYTHON
from collections import defaultdict


def reciprocal_rank_fusion(
    ranked_lists: list[list[str]],
    k: int = 60,
) -> list[tuple[str, float]]:
    scores = defaultdict(float)
    for ranked in ranked_lists:
        for rank, document_id in enumerate(ranked, start=1):
            scores[document_id] += 1.0 / (k + rank)

    return sorted(scores.items(), key=lambda item: item[1], reverse=True)

RRF technical system component,technical system component。technical system component Dense/Sparse technical system component,technical system component。

🔥 P0 High-Frequency Must-Know: technical system component BM25?
technical system component、technical system component、technical system component;BM25 technical system component。Hybrid technical system component,technical system component Reranker technical system component。

7. Query technical system component

technical system component:

  • “technical system component?”technical system component;
  • “technical system component A technical system component B”technical system component;
  • “technical system component XX-1042”technical system component,technical system component Sparse technical system component;
  • technical system componentknowledge bases;
  • technical system component,technical system component。

technical system component:

PYTHON
from typing import Literal
from pydantic import BaseModel


class RetrievalPlan(BaseModel):
    route: Literal["knowledge", "transaction_api", "no_retrieval"]
    queries: list[str]
    keyword_terms: list[str]
    filters: dict[str, str]

technical system component,technical system component Trace technical system component,technical system component。

8. Metadata Filter:technical system component,technical system component

technical system componentknowledge basestechnical system component:technical system component,technical system component“technical system component”。

technical system component:

  • tenant / organization;
  • department;
  • classification;
  • document status;
  • version;
  • language;
  • updated_at;
  • product / region。

technical system component,technical system component department="finance"

9. Rerank:technical system component

technical system component,technical system component;technical system component Cross-Encoder technical system component Reranker technical system component“technical system component—technical system component”technical system component,technical system component。

TEXT
Hybrid Top 50 -> technical system component -> Rerank -> Top 6 -> technical system component

Rerank technical system component,technical system component、technical system component。Pinecone technical system component Rerank technical system component RAG technical system component,technical system component Rerank results。

🔥 P0 High-Frequency Must-Know: technical system component?
technical system component Recall,technical system component;technical system component,technical system component。technical system component Top 3 technical system component,technical system component。

10. technical system component

technical system component。technical system component:

TEXT
[S1]
source: employee_handbook.pdf
page: 12
section: technical system component > technical system component
text: ...

[S2]
source: hr_policy_2026.md
section: technical system component
text: ...

technical system component [S1] technical system component。technical system component:

  1. technical system component ID technical system component;
  2. technical system component;
  3. technical system component,technical system component;
  4. technical system component。

technical system component。technical system component Citation Correctness technical system component。

11. RAG technical system component:technical system component,technical system component

11.1 technical system component

  • Recall@k:technical system component k technical system component;
  • Precision@k:technical system component k technical system component;
  • MRR:technical system component;
  • NDCG@k:technical system component。

technical system component 100 technical system component 82 technical system component Top 5 technical system component Chunk,technical system component Hit/Recall technical system component 82%。technical system component“technical system component”technical system component。

11.2 technical system component

  • technical system component、technical system component;
  • technical system component;
  • technical system component;
  • technical system component;
  • technical system component。

11.3 technical system component

  • technical system component;
  • technical system component;
  • technical system component;
  • P50/P95 technical system component;
  • technical system component。

🔥 P0 High-Frequency Must-Know: technical system component,technical system component?
technical system component;technical system component/technical system component/technical system component/technical system component。technical system component/Rerank technical system component。technical system component,technical system component、technical system component。

12. technical system component

technical system componenttechnical system componenttechnical system component
technical system componentDense technical system componentBM25、technical system component、technical system component、Hybrid
technical system componenttechnical system component/technical system componentversion filter、updated_at、technical system component
technical system componentPrompt technical system componenttechnical system component、technical system component、technical system component
technical system componentChunk technical system componenttechnical system component、Parent-Child、technical system component
Top technical system componenttechnical system componenttechnical system component、MMR、technical system component
technical system componenttechnical system componenttechnical system component ACL filter、technical system component
technical system componenttechnical system component、technical system componentparallelism、technical system component、technical system component Rerank technical system component
technical system componenttechnical system componenttechnical system component、technical system component、technical system component

13. technical system component RAG interfaces

PYTHON
from dataclasses import dataclass
from typing import Protocol


@dataclass
class Evidence:
    chunk_id: str
    text: str
    source_uri: str
    score: float


class Retriever(Protocol):
    async def search(self, query: str, filters: dict, top_k: int) -> list[Evidence]: ...


class Reranker(Protocol):
    async def rerank(
        self, query: str, candidates: list[Evidence], top_n: int
    ) -> list[Evidence]: ...


async def retrieve_context(
    query: str,
    filters: dict,
    retriever: Retriever,
    reranker: Reranker,
) -> list[Evidence]:
    candidates = await retriever.search(query, filters=filters, top_k=40)
    deduped = {item.chunk_id: item for item in candidates}
    ranked = await reranker.rerank(query, list(deduped.values()), top_n=6)
    return ranked

technical system component,technical system component Retriever technical system component Reranker,technical system component。

14. technical system component

technical system component A:technical system component

technical system component 20–50 technical system component,technical system component 60 technical system component:

  • 30 technical system component;
  • 10 technical system component/technical system component;
  • 10 technical system component;
  • 5 technical system component;
  • 5 technical system component。

technical system component/Chunk technical system component。

technical system component B:technical system component

technical system component:Dense、BM25、Hybrid、Hybrid+Rerank。technical system component Recall@5、MRR、P95 technical system component。

technical system component C:technical system component

technical system component、Chunk、technical system component、technical system component、Rerank、technical system component、technical system component、technical system component。technical system component,technical system component Trace。

15. technical system component

🔥 P0:RAG technical system component?

technical system component、technical system component、technical system component、technical system component、technical system component、technical system component、technical system component、Rerank、technical system component、technical system component、technical system component。technical system component。

🔥 P0:technical system component RAG technical system component?

technical system component;technical system component;technical system component;technical system component;technical system component;technical system component。technical system component。

🔥 P0:technical system componentvector databases?

technical system component、technical system component、technical system component、hybrid search、technical system component、technical system component、technical system component、technical system component、technical system component。technical system component ANN technical system component;technical system component。

⭐ P1:technical system component GraphRAG?

technical system component、technical system component,technical system component、technical system component、technical system component。technical system component、technical system component;technical system component FAQ technical system component Hybrid RAG。

⭐ P1:Embedding technical system component?

technical system component,technical system component;technical system component A/B;technical system component;technical system component;technical system component、technical system component、technical system component;technical system component。

16. technical system component

  • technical system component RAG technical system component;
  • technical system component Hybrid + RRF + Rerank;
  • technical system component;
  • technical system component、technical system component;
  • technical system component Trace technical system component;
  • technical system component、technical system component。

REFERENCES

References

  1. 01Hybrid search
  2. 02Rerank results

Series

AI Agent Development and Interview Guide

Next step

Continue with related topics

Continue along the same topic.

Browse latest news