YuktaiDocs v5.3.12

Ask page (RAG)

Ask page (RAG)

Answer questions from your own text, your page and your grid data. YuktAI finds the best passages and quotes them; an optional on-device model can then write the answer from only those passages.

What it is, honestly: the built-in search below (createContextIndex) is BM25 keyword retrieval with prefix matching and Telugu-aware tokens, in TypeScript or Rust. It finds passages that share words with the question. For meaning search (embeddings), use the new Ask page panel in Balanced mode.

New: the Ask page panel @yuktishaalaa/ask-page 0.1.0

A side panel that answers questions about the page from the page itself, highlights where each answer came from, and says so when the page does not answer it. It is running on this site now: press Ask in the top bar, or Ctrl + /.

Live on these docs

Open the panel and try one of these. Every answer shows its source; click it to see the passage highlighted on this page.

Also on its own page: the Ask page demo (opens in a new tab), with a Telugu section and a form to test the privacy filter.

Modes

Ask page modes
ModeSearchAnswerDownload
FastRust BM25 (WebAssembly, 52 KB)The best sentences from the page, quotedAbout 100 KB, nothing else
BalancedKeywords plus meaning (multilingual embeddings), merged with RRFChrome built-in AI if it is ready, else quotedAbout 118 MB once, after the visitor agrees
BestSame as BalancedChrome built-in AI, or WebLLM if the site enables itMore, once

Privacy and accessibility

Add it to your site

app/AskPage.tsx
"use client"
// app/AskPage.tsx: add once, in app/layout.tsx
import { useEffect } from "react"
import { mountAskPage } from "@yuktishaalaa/ask-page"

export default function AskPage() {
  useEffect(() => {
    mountAskPage({
      modes: ["fast", "balanced"],   // what visitors may pick
      questions: [{ text: "How do I apply?", path: "/scheme" }],
    })
  }, [])
  return null
}

Until the package is published on npm, download ask-page.global.js from the yuktai repo (opens in a new tab) and host it yourself, as this site does. Content Security Policy: allow worker-src blob: and 'wasm-unsafe-eval'; without them it still works, more slowly, on the page thread.

Without the panel

lib/ask.ts
import { AskPage } from "@yuktishaalaa/ask-page"

const page = new AskPage({ config: { modes: ["fast"] } })
const a = await page.ask("How do I install it?")
a.text      // the answer
a.kind      // "quote" | "ai" | "shortcut" | "unknown"
a.sources   // [{ ref: "Installation", excerpt, elements }]
lib/ask-graph.ts
import { askWithGraph, AskPageRetriever } from "@yuktishaalaa/ask-page/langgraph"

// the same five steps as a LangGraph.js StateGraph
const answer = await askWithGraph(page, "How do I install it?")

// or a LangChain retriever over the current page
const docs = await new AskPageRetriever(page, 5).invoke("model download size")

Full options, the architecture and the test results are in the package README (opens in a new tab).

Try it with your own text

Paste your FAQ, policy or help text. Each paragraph (separated by a blank line) is one passage.

Live demo

Also search

Loading…

app/help/AskHelp.tsx
"use client"
import { useMemo, useState } from "react"
import { createContextIndex } from "@yuktishaalaa/yuktai"

const documents = [
  { id: "leave", text: "Leave policy: every employee gets 24 days of paid leave a year." },
  { id: "wfh", text: "Work from home: staff may work from home two days a week." },
]

export function AskHelp() {
  // includePage: true also indexes the visible page text
  const index = useMemo(() => createContextIndex({ documents, includePage: false, engine: "rust" }), [])
  const [answer, setAnswer] = useState("")
  async function onAsk(question: string) {
    const r = await index.ask(question, { k: 4 })   // { answer, hits: [{ id, text, score }], generated }
    setAnswer(r.answer)
  }
  return (/* your input + <p aria-live="polite">{answer}</p> */ null)
}

Let a model write the answer (optional)

Pass generate to ask. YuktAI sends the model only the question and the top passages, so the answer stays grounded. Chrome's built-in Gemini Nano runs on the device; any API works too.

lib/generate.ts
// Chrome built-in AI (Gemini Nano). Falls back to the quoted answer when it is not available.
export async function generate(question: string, context: string) {
  const LM = (globalThis as any).LanguageModel
  if (!LM) throw new Error("No on-device model")
  const session = await LM.create()
  return session.prompt(
    "Answer only from these passages. If they do not answer it, say so.\n\n" + context + "\n\nQuestion: " + question
  )
}

// const r = await index.ask(question, { generate })   → r.generated === true

Questions about the page itself

askAboutPage knows the page structure: headings, landmarks, links, form fields and their problems.

Live demo

app/PageHelp.tsx
"use client"
import { askAboutPage, analyzePage } from "@yuktishaalaa/yuktai"

const r = await askAboutPage("Which fields are missing labels?")
// { intent, answer, targets, suggestions }
const outline = analyzePage()   // title, language, headings, landmarks, counts …

The built-in 💬 panel

The built-in search above with a ready-made UI, inside @yuktishaalaa/yuktai: AgenticPanel in React, mountAgenticPanel in plain HTML, or the 💬 button of YuktAIWrapper. For highlighted sources, Telugu answers and meaning search, use the Ask page panel.

Live demo

Loading…

app/help/page.tsx
"use client"
import { AgenticPanel } from "@yuktishaalaa/yuktai"

export default function Help() {
  return <AgenticPanel defaultTab="ask" engine="rust" />
}

// or site-wide, a floating 💬 button:
// <YuktAIWrapper showRag engine="rust">{children}</YuktAIWrapper>