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

# Query

> Find the passages that answer a question.

A query searches one namespace by meaning and by keywords at once, reranks the best candidates,
and returns one result per document: its best matching passage.

<CodeGroup>
  ```ts TypeScript theme={null}
  const results = await docs.query("how do refunds work?", {
    topK: 5,
    filter: { team: "support" },
  });
  ```

  ```bash curl theme={null}
  curl https://api.conare.ai/namespaces/docs/query \
    -H "Authorization: Bearer $CONARE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"query": "how do refunds work?", "top_k": 5, "filter": {"team": "support"}}'
  ```
</CodeGroup>

```json theme={null}
{
  "results": [
    { "id": "refunds", "text": "Refunds are available for 30 days after purchase.", "score": 0.91, "metadata": { "team": "support" } }
  ],
  "took_ms": 42
}
```

| Option | Default | |
| - | - | - |
| `top_k` (`topK`) | 10 | Results to return, 1-100. |
| `filter` | none | A [metadata filter](/concepts/filters). |
| `rerank` | `true` | Rerank candidates with the reranking model. Turn off for the lowest latency. |

Results are sorted best first. Scores compare results within one query; do not compare them
across queries.

## Embed and rerank

The models behind query are also available on their own, for example to rerank results you got
from somewhere else.

<CodeGroup>
  ```ts TypeScript theme={null}
  await conare.embed(["how do refunds work?"], { type: "query" });  // number[][]
  await conare.rerank("refund window", ["Orders ship in two days.", "Refunds within 30 days."], { topK: 1 });
  // [{ index: 1, score: 0.87, document: "Refunds within 30 days." }]
  ```

  ```bash curl theme={null}
  curl https://api.conare.ai/embed -H "Authorization: Bearer $CONARE_API_KEY" \
    -H "Content-Type: application/json" -d '{"input": ["how do refunds work?"], "type": "query"}'

  curl https://api.conare.ai/rerank -H "Authorization: Bearer $CONARE_API_KEY" \
    -H "Content-Type: application/json" -d '{"query": "refund window", "documents": ["a", "b"], "top_k": 1}'
  ```
</CodeGroup>

Use `type: "query"` for search queries and `type: "document"` (the default) for text you store.
