> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dreep.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Similar Images and Text Search

> Find images that look alike, or find images by describing them

Index an image once and you can find the images that look most like it, or find
images by describing them in plain words, such as "red sneakers on a white
background". Neither needs tags.

The Node.js examples use the [Node SDK](https://docs.dreep.cloud/node-sdk/introduction.md):

```typescript theme={null}
import { Dreep } from "dreep";

const dreep = new Dreep({ apiKey: process.env.DREEP_API_KEY });
```

## Index images as you upload them

Add `autoIndex=true` to an upload. The upload returns straight away and indexing
happens in the background.

```typescript Node.js theme={null}
const asset = await dreep.upload({
  file: fs.createReadStream("sneaker.jpg"),
  autoIndex: true,
});

asset.indexStatus; // "pending"
```

```bash cURL theme={null}
curl -X POST "https://api.dreep.cloud/api/v1/upload" \
  -H "Authorization: Bearer drp_live_xxxxx" \
  -F "file=@sneaker.jpg" \
  -F "autoIndex=true"
```

The response includes `"indexStatus": "pending"`. Presigned uploads take
`autoIndex` too and start indexing once the upload is confirmed. You can pass `autoTag` as well to tag the image too.

| `indexStatus` | Meaning |
| :- | :- |
| `pending` | Queued, or waiting for the upload to finish |
| `done` | The image can be searched |
| `failed` | The image couldn't be read or indexed |
| `skipped` | The account had no credit left for indexing |

## Index images you already have

```typescript Node.js theme={null}
const { indexStatus, cached } = await dreep.indexMedia({ id: asset.id });
```

```bash cURL theme={null}
curl -X POST "https://api.dreep.cloud/api/v1/media/2f928a3f-1d2a-4a2b/index" \
  -H "Authorization: Bearer drp_live_xxxxx"
```

See [Index Media](https://docs.dreep.cloud/api-reference/image-search/index-media.md).

## Find similar images

```typescript Node.js theme={null}
const lookalikes = await dreep.findSimilarMedia({ id: asset.id, limit: 8 });
```

```bash cURL theme={null}
curl "https://api.dreep.cloud/api/v1/media/2f928a3f-1d2a-4a2b/similar?limit=8" \
  -H "Authorization: Bearer drp_live_xxxxx"
```

Returns the project's indexed images that look most like this one, best first.
The image itself isn't included. Use it for "more like this" on a product page,
or to spot near-duplicates before they're published.

## Search by description

```typescript Node.js theme={null}
const results = await dreep.searchMedia({ query: "red sneakers on a white background" });

results[0].score; // 0.31
```

```bash cURL theme={null}
curl -G "https://api.dreep.cloud/api/v1/media/search" \
  -H "Authorization: Bearer drp_live_xxxxx" \
  --data-urlencode "q=red sneakers on a white background"
```

Write what you'd expect to see in the image. Queries can be up to 300
characters, and work best in English.

## Results and scores

Both searches return media items, like [List Media](https://docs.dreep.cloud/api-reference/media/list-media.md),
each with a `score` up to 1:

```json theme={null}
{
  "assets": [
    {
      "id": "2f928a3f-1d2a-4a2b",
      "filename": "red-sneaker.jpg",
      "url": "https://cdn.dreep.cloud/api/v1/fetch/2f928a3f-1d2a-4a2b",
      "tags": ["sneaker", "red"],
      "score": 0.31
    }
  ]
}
```

Similar images usually score 0.8 and up. Text matches score much lower, usually
0.2 to 0.35, even when they're good. To drop weak matches, pass `minScore`, and
pick a value for each kind of search separately.

Only indexed images can match. Results always come from the project the API key
belongs to.

## Billing

Indexing is charged per image at your plan's usage rate, from your included
usage or your credit. It works on every plan, pay as you go included. You
aren't charged when:

* The same image was indexed before. Dreep reuses the earlier result, and the
  response says `"cached": true`
* Indexing fails

Searching and finding similar images are free.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.