1:"$Sreact.fragment" 2:I[97333,["/_next/static/chunks/51cf3403df3ab8db.js","/_next/static/chunks/e1faea17a9e9ed14.js"],""] 70:I[39271,["/_next/static/chunks/1f465ca74a71847d.js","/_next/static/chunks/6628e8793cd41c7c.js"],"OutletBoundary"] 71:"$Sreact.suspense" 0:{"buildId":"3CCc4JxoD54WNKxdcWa8x","rsc":["$","$1","c",{"children":[["$","div",null,{"className":"min-h-screen bg-[var(--bg)]","children":["$","article",null,{"className":"section-container pt-32 max-w-3xl","children":[["$","$L2",null,{"href":"/blog","className":"inline-flex items-center gap-2 text-sm text-muted hover:text-accent transition-colors mb-8","children":[["$","svg",null,{"xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-arrow-left h-4 w-4","aria-hidden":"true","children":[["$","path","1l729n",{"d":"m12 19-7-7 7-7"}],["$","path","x3x0zl",{"d":"M19 12H5"}],"$undefined"]}],"Back to Blog"]}],["$","header",null,{"className":"mb-10","children":[["$","div",null,{"className":"flex flex-wrap items-center gap-3 text-sm text-muted mb-4","children":[["$","span",null,{"className":"inline-flex items-center gap-1.5","children":[["$","svg",null,{"xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-calendar h-3.5 w-3.5","aria-hidden":"true","children":[["$","path","1cmpym",{"d":"M8 2v4"}],["$","path","4m81vk",{"d":"M16 2v4"}],["$","rect","1hopcy",{"width":"18","height":"18","x":"3","y":"4","rx":"2"}],["$","path","8toen8",{"d":"M3 10h18"}],"$undefined"]}],"November 28, 2024"]}],["$","span",null,{"className":"inline-flex items-center gap-1.5","children":[["$","svg",null,{"xmlns":"http://www.w3.org/2000/svg","width":24,"height":24,"viewBox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":2,"strokeLinecap":"round","strokeLinejoin":"round","className":"lucide lucide-clock h-3.5 w-3.5","aria-hidden":"true","children":[["$","circle","1mglay",{"cx":"12","cy":"12","r":"10"}],["$","path","mmk7yg",{"d":"M12 6v6l4 2"}],"$undefined"]}],"7 min read"]}]]}],["$","h1",null,{"className":"font-[family-name:var(--font-outfit)] text-3xl font-bold tracking-tight text-foreground sm:text-4xl lg:text-5xl","children":"Optimizing RAG Pipelines for Healthcare: From 2s Latency to 200ms"}],["$","div",null,{"className":"mt-4 flex flex-wrap gap-2","children":[["$","span","RAG",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"RAG"}],["$","span","Healthcare AI",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"Healthcare AI"}],["$","span","Vector Databases",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"Vector Databases"}],["$","span","Qdrant",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"Qdrant"}],["$","span","Performance",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"Performance"}],["$","span","LangChain",{"className":"rounded-full border border-[var(--card-border)] bg-[var(--card-bg)] px-3 py-1 text-xs text-muted","children":"LangChain"}]]}]]}],["$","div",null,{"className":"prose-custom","children":[["$","h1",null,{"className":"font-[family-name:var(--font-outfit)] text-3xl font-bold tracking-tight text-foreground mt-10 mb-4 first:mt-0","children":"Optimizing RAG Pipelines for Healthcare: From 2s Latency to 200ms"}],"\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"When we launched Genio Pulse — our medical AI assistant serving 5,000+ doctors — the initial RAG pipeline took 2-3 seconds per query. For a tool that doctors use mid-consultation, that was unacceptable. Over six months of iterative optimization, we brought it down to under 200ms while improving retrieval relevance from 78% to 95%."}],"\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"This post documents every optimization we made, in the order we implemented them. If you're building RAG for production, these lessons will save you months."}],"\n","$L3","\n","$L4","\n","$L5","\n","$L6","\n","$L7","\n","$L8","\n","$L9","\n","$La","\n","$Lb","\n","$Lc","\n","$Ld","\n","$Le","\n","$Lf","\n","$L10","\n","$L11","\n","$L12","\n","$L13","\n","$L14","\n","$L15","\n","$L16","\n","$L17","\n","$L18","\n","$L19","\n","$L1a","\n","$L1b","\n","$L1c","\n","$L1d","\n","$L1e","\n","$L1f","\n","$L20","\n","$L21","\n","$L22","\n","$L23","\n","$L24","\n","$L25","\n","$L26","\n","$L27","\n","$L28","\n","$L29","\n","$L2a","\n","$L2b","\n","$L2c","\n","$L2d","\n","$L2e","\n","$L2f","\n","$L30","\n","$L31","\n","$L32"]}]]}]}],["$L33"],"$L34"]}],"loading":null,"isPartial":false} 3:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"The Starting Point"}] 4:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Our initial architecture was textbook:"}] 5:["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","children":"User Query → Embed → Vector Search (Qdrant) → Top-K → LLM → Response\n"}]}] 6:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["$","strong",null,{"className":"font-semibold text-foreground","children":"Baseline metrics:"}]}] 7:["$","ul",null,{"className":"list-disc list-inside space-y-2 text-muted mb-5","children":["\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Embedding latency: ~100ms"}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Vector search: ~150ms"}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":"LLM generation: ~1500ms"}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Total: ~2000ms"}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Retrieval relevance (manual eval): 78%"}],"\n"]}] 8:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"The LLM generation time is mostly out of our control (model provider latency), so we focused on everything else — and discovered that better retrieval actually reduces generation time too, because the LLM gets more relevant context and generates faster, more focused answers."}] 9:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Optimization 1: Chunking Strategy (78% → 84% relevance)"}] a:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Our first mistake was using a naive text splitter with fixed chunk sizes. Medical literature has structure — headings, sections, bullet points, references — and splitting mid-paragraph destroys context."}] b:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["$","strong",null,{"className":"font-semibold text-foreground","children":"Before:"}]}] c:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":"# Naive: fixed 1000-char chunks with 200-char overlap"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":"text_splitter "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" RecursiveCharacterTextSplitter("}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" chunk_size"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"1000"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" chunk_overlap"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"200"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":")"}]}]]}]}]}] d:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["$","strong",null,{"className":"font-semibold text-foreground","children":"After:"}]}] e:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":"# Semantic chunking that respects document structure"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"class"}],["$","span",null,{"style":{"color":"#F69D50"},"children":" MedicalDocumentChunker"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" chunk"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self, document: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", metadata: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"dict"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":") -> list[Document]:"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sections "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".split_by_headers(document)"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" chunks "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" []"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" for"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" section "}],["$","span",null,{"style":{"color":"#F47067"},"children":"in"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sections:"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" if"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" len"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(section.content) "}],["$","span",null,{"style":{"color":"#F47067"},"children":"<"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 512"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Small sections stay intact"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" chunks.append(Document("}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" content"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"section.content,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" metadata"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"{"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" **"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"metadata,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"section\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": section.header,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"chunk_type\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": "}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"full_section\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" }"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" ))"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" else"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n","$L35","\n","$L36","\n","$L37","\n","$L38","\n","$L39","\n","$L3a","\n","$L3b","\n","$L3c","\n","$L3d","\n","$L3e","\n","$L3f","\n","$L40","\n","$L41","\n","$L42","\n","$L43","\n","$L44","\n","$L45","\n","$L46"]}]}]}] f:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["$","strong",null,{"className":"font-semibold text-foreground","children":"Key changes:"}]}] 10:["$","ul",null,{"className":"list-disc list-inside space-y-2 text-muted mb-5","children":["\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Chunk size: 1000 → 512 tokens (smaller chunks = more precise retrieval)"}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Overlap: character-based → sentence-based (2 sentences overlap)"}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Structure-aware: respect section boundaries"}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":"Prepend section header to each chunk (preserves context)"}],"\n"]}] 11:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Impact:"}]," Relevance jumped from 78% to 84%. Latency unchanged."]}] 12:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Optimization 2: Hybrid Search (84% → 90% relevance)"}] 13:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Pure vector similarity misses exact medical terms. If a doctor searches for \"metformin 500mg side effects,\" pure semantic search might return results about diabetes medications generally. We need exact keyword matching too."}] 14:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"from"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" qdrant_client.models "}],["$","span",null,{"style":{"color":"#F47067"},"children":"import"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" SparseVector"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"class"}],["$","span",null,{"style":{"color":"#F69D50"},"children":" HybridSearcher"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" search"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self, query: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", limit: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"int"}],["$","span",null,{"style":{"color":"#F47067"},"children":" ="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 10"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":") -> list[SearchResult]:"}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Dense vector search (semantic understanding)"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" dense_results "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".qdrant.search("}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" collection_name"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"medical_docs\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" query_vector"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"("}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"dense\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".embed(query)),"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" limit"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"limit "}],["$","span",null,{"style":{"color":"#F47067"},"children":"*"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 2"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", "}],["$","span",null,{"style":{"color":"#768390"},"children":"# Fetch more for fusion"}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Sparse vector search (keyword matching via BM25)"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sparse_vector "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".bm25_encoder.encode(query)"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sparse_results "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".qdrant.search("}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" collection_name"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"medical_docs\""}],"$L47"]}],"\n","$L48","\n","$L49","\n","$L4a","\n","$L4b","\n","$L4c","\n","$L4d","\n","$L4e","\n","$L4f","\n","$L50","\n","$L51","\n","$L52","\n","$L53","\n","$L54","\n","$L55","\n","$L56","\n","$L57","\n","$L58","\n","$L59","\n","$L5a","\n","$L5b"]}]}]}] 15:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Why RRF over weighted scoring:"}]," Reciprocal Rank Fusion doesn't require tuning weights between dense and sparse scores. It's robust and works well out of the box."]}] 16:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Impact:"}]," Relevance improved from 84% to 90%. Search latency increased slightly (~20ms) due to dual search, but the quality improvement was worth it."]}] 17:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Optimization 3: Metadata Filtering (latency: 150ms → 40ms)"}] 18:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Most queries have implicit constraints that we can filter on before vector search:"}] 19:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" build_filters"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self, query: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", doctor_profile: DoctorProfile):"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" filters "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" []"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Filter by medical specialty"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" if"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" doctor_profile.specialty:"}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" filters.append("}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" FieldCondition("}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" key"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"specialty\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" match"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"MatchAny("}],["$","span",null,{"style":{"color":"#F69D50"},"children":"any"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".related_specialties("}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" doctor_profile.specialty"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )),"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Filter by recency (prefer recent medical literature)"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" filters.append("}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" FieldCondition("}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" key"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"publication_year\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" range"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"Range("}],["$","span",null,{"style":{"color":"#F69D50"},"children":"gte"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"2019"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"), "}],["$","span",null,{"style":{"color":"#768390"},"children":"# Last 5 years"}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Filter by evidence level (prefer high-quality sources)"}]}],"\n","$L5c","\n","$L5d","\n","$L5e","\n","$L5f","\n","$L60","\n","$L61","\n","$L62","\n","$L63"]}]}]}] 1a:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Impact:"}]," By filtering before vector search, Qdrant searches a much smaller subset. Latency dropped from 150ms to 40ms, and relevance improved to 92% (irrelevant specialties no longer pollute results)."]}] 1b:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Optimization 4: Reranking (90% → 95% relevance)"}] 1c:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Vector similarity is a rough first pass. A cross-encoder reranker scores each query-document pair more accurately:"}] 1d:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"from"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sentence_transformers "}],["$","span",null,{"style":{"color":"#F47067"},"children":"import"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" CrossEncoder"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"class"}],["$","span",null,{"style":{"color":"#F69D50"},"children":" Reranker"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" __init__"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self):"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".model "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" CrossEncoder("}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"cross-encoder/ms-marco-MiniLM-L-12-v2\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" max_length"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"512"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" rerank"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self, query: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", documents: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"list"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", top_k: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"int"}],["$","span",null,{"style":{"color":"#F47067"},"children":" ="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 5"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"):"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" pairs "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" [(query, doc.content) "}],["$","span",null,{"style":{"color":"#F47067"},"children":"for"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" doc "}],["$","span",null,{"style":{"color":"#F47067"},"children":"in"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" documents]"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" scores "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".model.predict(pairs)"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" scored_docs "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" list"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"("}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"zip"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(documents, scores))"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" scored_docs.sort("}],["$","span",null,{"style":{"color":"#F69D50"},"children":"key"}],["$","span",null,{"style":{"color":"#F47067"},"children":"=lambda"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" x: x["}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"1"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"], "}],"$L64","$L65","$L66","$L67"]}],"\n","$L68","\n","$L69"]}]}]}] 1e:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["$","strong",null,{"className":"font-semibold text-foreground","children":"Pipeline after reranking:"}]}] 1f:["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","children":"Query → Hybrid Search (top 20) → Rerank (top 5) → LLM\n"}]}] 20:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Impact:"}]," Relevance went from 92% to 95%. Reranking adds ~30ms but the LLM gets much better context, which actually reduced generation time by ~200ms (shorter, more focused responses)."]}] 21:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Optimization 5: Embedding Cache (100ms → 5ms for repeated queries)"}] 22:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Doctors often ask similar questions. We cache embeddings in Redis:"}] 23:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"class"}],["$","span",null,{"style":{"color":"#F69D50"},"children":" CachedEmbedder"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" __init__"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self, redis_client, embedder, ttl"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"3600"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"):"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".redis "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" redis_client"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".embedder "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" embedder"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".ttl "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" ttl"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" embed"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self, text: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":") -> list["}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"float"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"]:"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" cache_key "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#F47067"},"children":" f"}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"emb:"}],["$","span",null,{"style":{"color":"#F47067"},"children":"{"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"hashlib.md5(text.encode()).hexdigest()"}],["$","span",null,{"style":{"color":"#F47067"},"children":"}"}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\""}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" cached "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".redis.get(cache_key)"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" if"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" cached:"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" json.loads(cached)"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" embedding "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".embedder.embed_query(text)"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".redis.setex(cache_key, "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".ttl, json.dumps(embedding))"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],"$L6a"]}]]}]}]}] 24:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Impact:"}]," For cache hits (~40% of queries), embedding latency drops from 100ms to 5ms."]}] 25:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Optimization 6: Streaming + Parallel Processing"}] 26:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"Instead of sequential execution, we parallelize independent steps:"}] 27:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"import"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" asyncio"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"async"}],["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" rag_query"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(query: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", doctor: DoctorProfile):"}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Run embedding and filter building in parallel"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" embedding_task "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" asyncio.create_task(embedder.aembed(query))"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" filters "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" build_filters(query, doctor)"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" embedding "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#F47067"},"children":" await"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" embedding_task"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Hybrid search (dense + sparse in parallel internally)"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" results "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#F47067"},"children":" await"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" hybrid_searcher.asearch("}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" embedding"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"embedding,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" filters"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"filters,"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" limit"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"20"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Rerank"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" top_docs "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" reranker.rerank(query, results, "}],["$","span",null,{"style":{"color":"#F69D50"},"children":"top_k"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"5"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":")"}]]}],"\n",["$","span",null,{"data-line":"","children":" "}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Stream LLM response (don't wait for full generation)"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" async"}],["$","span",null,{"style":{"color":"#F47067"},"children":" for"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" chunk "}],"$L6b","$L6c"]}],"\n","$L6d","\n","$L6e","\n","$L6f"]}]}]}] 28:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Impact:"}]," Total perceived latency dropped to ~200ms for first token (streaming means the doctor sees text appearing immediately)."]}] 29:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"The Final Architecture"}] 2a:["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","children":"Query\n ├─ [Parallel] Cache Check → Embed (5-100ms)\n ├─ [Parallel] Build Filters (1ms)\n │\n ├─ Hybrid Search (dense + sparse) with Filters (40ms)\n ├─ Rerank Top 20 → Top 5 (30ms)\n │\n └─ Stream LLM Response (first token: ~150ms)\n\nTotal to first token: ~200ms\nTotal to complete response: ~800ms\n"}]}] 2b:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Monitoring in Production"}] 2c:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"We track these metrics continuously:"}] 2d:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":"| Metric | Target | Alert Threshold |\n|--------|--------|----------------|\n| P50 latency (to first token) | under 200ms | over 500ms |\n| P99 latency (to first token) | under 500ms | over 1500ms |\n| Retrieval relevance (weekly eval) | above 93% | below 88% |\n| Cache hit rate | above 35% | below 20% |\n| Embedding API errors | below 0.1% | above 1% |\n| Cost per query | under $0.03 | over $0.10 |"}] 2e:["$","figure",null,{"data-rehype-pretty-code-figure":"","children":["$","pre",null,{"className":"overflow-x-auto rounded-xl border border-[var(--card-border)] bg-[var(--surface)] p-4 text-sm mb-5","style":{"backgroundColor":"#22272e","color":"#adbac7"},"tabIndex":"0","data-language":"python","data-theme":"github-dark-dimmed","children":["$","code",null,{"className":"rounded bg-[var(--card-bg)] px-1.5 py-0.5 text-sm font-mono text-accent","data-language":"python","data-theme":"github-dark-dimmed","style":{"display":"grid"},"children":[["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":"# We log every query for continuous evaluation"}]}],"\n",["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#DCBDFB"},"children":"@dataclass"}]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":"class"}],["$","span",null,{"style":{"color":"#F69D50"},"children":" QueryLog"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":":"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" query: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" doctor_specialty: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" retrieved_doc_ids: list["}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"str"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"]"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" reranker_scores: list["}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"float"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"]"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" embedding_latency_ms: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"float"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" search_latency_ms: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"float"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" rerank_latency_ms: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"float"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" generation_latency_ms: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"float"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" total_latency_ms: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"float"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" cache_hit: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"bool"}]]}],"\n",["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" token_usage: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"dict"}]]}]]}]}]}] 2f:["$","h2",null,{"className":"font-[family-name:var(--font-outfit)] text-2xl font-semibold tracking-tight text-foreground mt-10 mb-3","children":"Lessons Learned"}] 30:["$","ol",null,{"className":"list-decimal list-inside space-y-2 text-muted mb-5","children":["\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Chunking quality > embedding model quality."}]," We got a bigger relevance boost from better chunking than from upgrading embedding models."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Filter before you search."}]," Metadata filtering is free performance. Use every signal you have (specialty, recency, document type) to narrow the search space."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Reranking is almost always worth it."}]," The 30ms cost pays for itself by giving the LLM better context (faster, more accurate responses)."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Cache everything you can."}]," Embeddings, search results, even full responses for common queries. In healthcare, many questions are variations of the same few hundred queries."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Measure retrieval quality separately from generation quality."}]," A bad retrieval + good LLM still produces a bad answer. Track retrieval relevance independently."]}],"\n"]}],"\n",["$","li",null,{"className":"text-base leading-relaxed","children":["\n",["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":[["$","strong",null,{"className":"font-semibold text-foreground","children":"Stream, don't wait."}]," Perceived latency matters more than total latency. First-token-time is the metric that determines user satisfaction."]}],"\n"]}],"\n"]}] 31:["$","hr",null,{"className":"my-8 border-[var(--card-border)]"}] 32:["$","p",null,{"className":"text-base leading-relaxed text-muted mb-5","children":["$","em",null,{"children":"These optimizations didn't happen overnight — they were spread across six months of iterative improvement, driven by user feedback and continuous monitoring. The key is having good observability so you know where to focus next."}]}] 33:["$","script","script-0",{"src":"/_next/static/chunks/e1faea17a9e9ed14.js","async":true}] 34:["$","$L70",null,{"children":["$","$71",null,{"name":"Next.MetadataOutlet","children":"$@72"}]}] 35:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Large sections get sentence-aware splitting"}]}] 36:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sub_chunks "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".sentence_split("}]]}] 37:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" section.content,"}]}] 38:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" target_size"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"512"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}] 39:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" overlap_sentences"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"2"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}] 3a:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}] 3b:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" for"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" i, sub "}],["$","span",null,{"style":{"color":"#F47067"},"children":"in"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" enumerate"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(sub_chunks):"}]]}] 3c:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" chunks.append(Document("}]}] 3d:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" content"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#F47067"},"children":"f"}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"Section: "}],["$","span",null,{"style":{"color":"#F47067"},"children":"{"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"section.header"}],["$","span",null,{"style":{"color":"#F47067"},"children":"}\\n\\n{"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"sub"}],["$","span",null,{"style":{"color":"#F47067"},"children":"}"}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}] 3e:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" metadata"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"{"}]]}] 3f:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" **"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"metadata,"}]]}] 40:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"section\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": section.header,"}]]}] 41:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"chunk_index\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": i,"}]]}] 42:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"chunk_type\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":": "}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"sub_section\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}] 43:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" }"}]}] 44:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" ))"}]}] 45:["$","span",null,{"data-line":"","children":" "}] 46:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" chunks"}]]}] 47:["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}] 48:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" query_vector"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"("}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"sparse\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", SparseVector("}]]}] 49:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" indices"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"sparse_vector.indices,"}]]}] 4a:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" values"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"sparse_vector.values,"}]]}] 4b:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )),"}]}] 4c:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" limit"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"limit "}],["$","span",null,{"style":{"color":"#F47067"},"children":"*"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 2"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}] 4d:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}] 4e:["$","span",null,{"data-line":"","children":" "}] 4f:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#768390"},"children":" # Reciprocal Rank Fusion"}]}] 50:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" self"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":".rrf_fusion(dense_results, sparse_results, "}],["$","span",null,{"style":{"color":"#F69D50"},"children":"limit"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"limit)"}]]}] 51:["$","span",null,{"data-line":"","children":" "}] 52:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" def"}],["$","span",null,{"style":{"color":"#DCBDFB"},"children":" rrf_fusion"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(self, "}],["$","span",null,{"style":{"color":"#F47067"},"children":"*"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"result_lists, limit: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"int"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", k: "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"int"}],["$","span",null,{"style":{"color":"#F47067"},"children":" ="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 60"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"):"}]]}] 53:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#96D0FF"},"children":" \"\"\"Combine rankings using Reciprocal Rank Fusion.\"\"\""}]}] 54:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" scores "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" {}"}]]}] 55:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" for"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" results "}],["$","span",null,{"style":{"color":"#F47067"},"children":"in"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" result_lists:"}]]}] 56:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" for"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" rank, result "}],["$","span",null,{"style":{"color":"#F47067"},"children":"in"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" enumerate"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(results):"}]]}] 57:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" doc_id "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" result.id"}]]}] 58:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" scores[doc_id] "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" scores.get(doc_id, "}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"0"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":") "}],["$","span",null,{"style":{"color":"#F47067"},"children":"+"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 1.0"}],["$","span",null,{"style":{"color":"#F47067"},"children":" /"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" (k "}],["$","span",null,{"style":{"color":"#F47067"},"children":"+"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" rank "}],["$","span",null,{"style":{"color":"#F47067"},"children":"+"}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" 1"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":")"}]]}] 59:["$","span",null,{"data-line":"","children":" "}] 5a:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sorted_docs "}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":" sorted"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"(scores.items(), "}],["$","span",null,{"style":{"color":"#F69D50"},"children":"key"}],["$","span",null,{"style":{"color":"#F47067"},"children":"=lambda"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" x: x["}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"1"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"], "}],["$","span",null,{"style":{"color":"#F69D50"},"children":"reverse"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#6CB6FF"},"children":"True"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":")"}]]}] 5b:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" sorted_docs[:limit]"}]]}] 5c:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" filters.append("}]}] 5d:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" FieldCondition("}]}] 5e:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" key"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"evidence_level\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":","}]]}] 5f:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" match"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"MatchAny("}],["$","span",null,{"style":{"color":"#F69D50"},"children":"any"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"["}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"systematic_review\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", "}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"rct\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":", "}],["$","span",null,{"style":{"color":"#96D0FF"},"children":"\"meta_analysis\""}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"]),"}]]}] 60:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}] 61:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" )"}]}] 62:["$","span",null,{"data-line":"","children":" "}] 63:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" Filter("}],["$","span",null,{"style":{"color":"#F69D50"},"children":"must"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"filters)"}]]}] 64:["$","span",null,{"style":{"color":"#F69D50"},"children":"reverse"}] 65:["$","span",null,{"style":{"color":"#F47067"},"children":"="}] 66:["$","span",null,{"style":{"color":"#6CB6FF"},"children":"True"}] 67:["$","span",null,{"style":{"color":"#ADBAC7"},"children":")"}] 68:["$","span",null,{"data-line":"","children":" "}] 69:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" return"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" [doc "}],["$","span",null,{"style":{"color":"#F47067"},"children":"for"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" doc, score "}],["$","span",null,{"style":{"color":"#F47067"},"children":"in"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" scored_docs[:top_k]]"}]]}] 6a:["$","span",null,{"style":{"color":"#ADBAC7"},"children":" embedding"}] 6b:["$","span",null,{"style":{"color":"#F47067"},"children":"in"}] 6c:["$","span",null,{"style":{"color":"#ADBAC7"},"children":" llm.astream("}] 6d:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F69D50"},"children":" prompt"}],["$","span",null,{"style":{"color":"#F47067"},"children":"="}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":"build_prompt(query, top_docs),"}]]}] 6e:["$","span",null,{"data-line":"","children":["$","span",null,{"style":{"color":"#ADBAC7"},"children":" ):"}]}] 6f:["$","span",null,{"data-line":"","children":[["$","span",null,{"style":{"color":"#F47067"},"children":" yield"}],["$","span",null,{"style":{"color":"#ADBAC7"},"children":" chunk"}]]}] 72:null