Skip to content

Incremental engine for long horizon agents 🌟 Star if you like it!

7.8 KB
Raw Blame
---
// Search images by text: the four photos the example ships in img/, the CLIP
// model that embeds both images and text (openai/clip-vit-large-patch14,
// 768-d per the README), the Qdrant collection ImageSearch with its filename
// payload, and the README's query "long neck" returning the giraffe first.
// The payload filename is str(file.file_path.path), which includes img/.
// Runs live inside api.py, so giraffe.jpg is the photo dropped in (Ξ”).
interface Props { size?: 'hero' | 'card' }
const { size = 'hero' } = Astro.props;
const B = 'https://cocoindex.io/blobs/docs-v1/img/examples/image-search/scene';
const photos = [
  { f: 'cat1.jpeg', src: 'cat1', w: 320, h: 334 },
  { f: 'dog1.jpeg', src: 'dog1', w: 320, h: 240 },
  { f: 'elephant1.jpg', src: 'elephant1', w: 320, h: 213 },
  { f: 'giraffe.jpg', src: 'giraffe', w: 320, h: 180, d: true },
];
---
{size === 'hero' ? (
  <div class="is">
    <div class="sc-row is-top">
      <div class="sc-col is-src">
        <span class="sc-cap">Photos in img/</span>
        <div class="is-grid">
          {photos.map((p) => (
            <div class={`is-tile${p.d ? ' sc-delta' : ''}`}>
              <img src={`${B}/${p.src}.webp`} width={p.w} height={p.h} alt="" loading="lazy" decoding="async" />
              <span class="is-name"><span>{p.f}</span></span>{p.d && <span class="sc-dmark is-mark">Ξ”</span>}
            </div>
          ))}
        </div>
        <span class="sc-live">api.py watches img/ in live mode</span>
      </div>
      <span class="sc-to"></span>
      <div class="sc-col is-mid">
        <span class="sc-cap">One model, two encoders</span>
        <div class="sc-panel">
          <div class="sc-panel-h is-model"><span class="sc-ico i-model"></span><span class="is-mname"><span class="sc-dim">openai/</span><br />clip-vit-<wbr />large-<wbr />patch14</span></div>
          <div class="sc-panel-b">
            <span class="sc-li"><span class="sc-ico i-image"></span><span>get_image_features</span></span>
            <span class="is-sub">each photo, at index time</span>
            <span class="sc-li"><span class="sc-ico i-search"></span><span>get_text_features</span></span>
            <span class="is-sub">your words, at query time</span>
          </div>
        </div>
        <span class="sc-cap is-fine">Both land in the same 768-d space</span>
      </div>
      <span class="sc-to"></span>
      <div class="sc-col is-tgt">
        <span class="sc-cap">Qdrant</span>
        <div class="sc-panel">
          <div class="sc-panel-h"><span class="sc-ico i-db"></span>ImageSearch</div>
          <table class="sc-table">
            <thead><tr><th>payload filename</th></tr></thead>
            <tbody>
              <tr><td>img/cat1.jpeg</td></tr>
              <tr><td>img/dog1.jpeg</td></tr>
              <tr><td>img/elephant1.jpg</td></tr>
              <tr class="sc-delta"><td><span class="sc-dtext">img/giraffe.jpg</span></td></tr>
            </tbody>
          </table>
        </div>
        <span class="sc-cap is-fine">One point per photo, id = uuid5 of the path, cosine distance</span>
      </div>
    </div>

    <div class="is-search">
      <span class="sc-cap">Search by meaning at localhost:5173</span>
      <div class="sc-query"><span class="sc-ico i-search"></span><span>long neck</span></div>
      <div class="sc-row is-res">
        <figure class="is-hit">
          <img src={`${B}/giraffe.webp`} width="320" height="180" alt="" loading="lazy" decoding="async" />
          <figcaption><span class="r">1</span><span>img/giraffe.jpg</span></figcaption>
        </figure>
        <div class="is-rest">
          <p class="sc-quote">The giraffe ranks first, then the other animals by CLIP similarity. <b>No photo was ever tagged with a word.</b></p>
          <div class="is-thumbs">
            <img src={`${B}/cat1.webp`} width="320" height="334" alt="" loading="lazy" decoding="async" />
            <img src={`${B}/dog1.webp`} width="320" height="240" alt="" loading="lazy" decoding="async" />
            <img src={`${B}/elephant1.webp`} width="320" height="213" alt="" loading="lazy" decoding="async" />
          </div>
        </div>
      </div>
    </div>
  </div>
) : (
  <div class="is-card">
    <div class="sc-row sc-keep">
      <div class="is-cgrid">
        {photos.map((p) => (
          <img class={p.d ? 'is-cd' : ''} src={`${B}/${p.src}.webp`} width={p.w} height={p.h} alt="" loading="lazy" decoding="async" />
        ))}
      </div>
      <span class="sc-to"></span>
      <div class="sc-col is-cres">
        <div class="sc-query"><span class="sc-ico i-search"></span><span>long neck</span></div>
        <div class="is-chit">
          <img src={`${B}/giraffe.webp`} width="320" height="180" alt="" loading="lazy" decoding="async" />
          <span class="sc-mono">1 Β· img/giraffe.jpg</span>
        </div>
      </div>
    </div>
  </div>
)}

<style>
  .is { display: flex; flex-direction: column; gap: 18px; }
  .is-top { gap: 10px; }
  .is-src { flex: 1.3 1 0; }
  .is-mid { flex: 1.05 1 0; }
  .is-tgt { flex: 0.9 1 0; }
  .is-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .is-tile { position: relative; margin: 0; border: 1px solid var(--sc-line); border-radius: 7px; overflow: hidden; background: var(--sc-panel); }
  .is-tile img { display: block; width: 100%; height: 72px; object-fit: cover; }
  .is-tile.sc-delta { border-color: var(--sc-delta) !important; }
  .is-name { display: flex; align-items: center; gap: 6px; padding: 4px 6px; font-family: var(--mono); font-size: 12px; color: var(--sc-muted); min-width: 0; }
  .is-name > span:first-child { min-width: 0; overflow-wrap: anywhere; }
  .is-mark { position: absolute; top: 5px; right: 5px; }
  .is-model { white-space: normal; align-items: flex-start; line-height: 1.35; }
  .is-model > span.is-mname.is-mname { white-space: normal; overflow: visible; }
  .is-model .sc-ico { margin-top: 1px; }
  .sc-delta .is-name > span:first-child { color: var(--sc-delta-text); }
  .is-sub { font-size: 12px; color: var(--sc-dim); padding-left: 22px; margin-top: -3px; }
  .is-mid .sc-li { font-size: 12px; }
  .is-fine { font-weight: 400; }
  .is-tgt .sc-table td { white-space: normal; overflow-wrap: anywhere; }
  .is-search { display: flex; flex-direction: column; gap: 8px; padding-top: 16px; border-top: 1px solid var(--sc-line); }
  .is-res { gap: 14px; align-items: center; }
  .is-hit { margin: 0; flex: 0 0 240px; border: 1px solid var(--sc-line-2); border-radius: 8px; overflow: hidden; background: var(--sc-panel); }
  .is-hit img { display: block; width: 100%; height: 132px; object-fit: cover; }
  .is-hit figcaption { display: flex; gap: 8px; padding: 6px 10px; font-family: var(--mono); font-size: 12px; color: var(--sc-ink); }
  .is-hit .r { color: var(--sc-dim); }
  .is-rest { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
  .is-rest .sc-quote { margin: 0; }
  .is-thumbs { display: flex; gap: 6px; }
  .is-thumbs img { width: 64px; height: 48px; object-fit: cover; border-radius: 5px; border: 1px solid var(--sc-line); opacity: 0.7; }
  @container (max-width: 560px) {
    .is-hit { flex: none; width: 100%; }
    .is-tile img { height: 64px; }
  }

  .is-card { height: 100%; display: flex; align-items: center; }
  .is-card > .sc-row { width: 100%; align-items: center; }
  .is-cgrid { flex: 0 0 132px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .is-cgrid img { display: block; width: 100%; height: 50px; object-fit: cover; border-radius: 5px; border: 1px solid var(--sc-line); }
  .is-cgrid img.is-cd { border-color: var(--sc-delta); }
  .is-cres { gap: 6px; }
  .is-chit { border: 1px solid var(--sc-line-2); border-radius: 6px; overflow: hidden; background: var(--sc-panel); }
  .is-chit img { display: block; width: 100%; height: 68px; object-fit: cover; }
  .is-chit .sc-mono { display: block; padding: 3px 7px; color: var(--sc-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
</style>