aiellie

Search

Find a component, template or page

GitHub
Components

Retrieved Sources

The passages a reply was built from: each document with where the passage sits and how relevant it scored, opening to the passage, with those under a threshold muted.

  1. Full-time employees accrue 1.5 days of paid leave per month, up to a maximum of 30 days carried into the next year.
Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/retrieved-sources"

shadcn needs the @aiellie registry in components.json first. npx aiellie add retrieved-sources adds it on its first run, then installs the same way.

Retrieved Sources lists the passages a reply was built from when it searched your own documents. Each row names the document, where in it the passage sits, and how relevant it scored, and opens to show the passage itself.

With a threshold, passages that scored under it are muted, so it's clear which ones the model was given. For pages from the web, use Sources.

Getting started

  1. List what was retrieved

    Scores run from 0 to 1, as most vector stores return them.

    components/reply-sources.tsx
    import {
      RetrievedSource,
      RetrievedSources,
    } from "@/components/aiellie/retrieved-sources"
    
    export function ReplySources({ chunks }: { chunks: Chunk[] }) {
      return (
        <RetrievedSources threshold={0.5}>
          {chunks.map((chunk) => (
            <RetrievedSource
              key={chunk.id}
              title={chunk.document}
              location={`p. ${chunk.page}`}
              score={chunk.score}
            >
              {chunk.text}
            </RetrievedSource>
          ))}
        </RetrievedSources>
      )
    }

Anatomy

<ol data-slot="retrieved-sources">
  <li data-slot="retrieved-source" data-below-threshold>
    <button /> {/* icon, title, location, score, chevron */}
    <blockquote /> {/* the passage, when opened */}
  </li>
</ol>

Each row is a Base UI Collapsible. A row with no passage doesn't open and shows no chevron. The score is drawn as a short bar and printed to two places, and read out as its relevance.

Examples

Without scores

Leave score out for search that doesn't rank, and pass your own icon.

API reference

RetrievedSources

PropTypeDefaultDescription
thresholdnumberPassages scoring under it are muted as not used.

All other ol props are forwarded.

RetrievedSource

PropTypeDefaultDescription
titleReactNoderequiredThe document.
locationReactNodeWhere in it, like "p. 4".
scorenumberRelevance, from 0 to 1.
iconIconSvgElementa file
childrenReactNodeThe passage, shown when opened.
open, defaultOpen, onOpenChangeAs on Collapsible.Root.