> For the complete documentation index, see [llms.txt](https://docs.telys.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.telys.ai/working-with-data/search-by-text.md).

# Search by text

`search_text` is the text query path: pass a string, Telys embeds it with the collection's embedder and runs the same nearest-neighbor search as [`search`](/working-with-data/search-by-vector.md). It is the counterpart to `add_texts` — if you added text, you search text.

## Signature

```python
Collection.search_text(
    text,
    top_k=10,
    where=None,
    explain=False,
    target_recall=None,
    with_metadata=False,
) -> dict
```

| Parameter       | Type                 | Default | Meaning                                                                                             |
| --------------- | -------------------- | ------- | --------------------------------------------------------------------------------------------------- |
| `text`          | `str`                | —       | The query string. Embedded with the collection's embedder (via `embed_queries`).                    |
| `top_k`         | `int`                | `10`    | Maximum number of results to return.                                                                |
| `where`         | `Eq \| dict \| None` | `None`  | Restrict to a partition/filter column (see [Filter results](/working-with-data/filter-results.md)). |
| `explain`       | `bool`               | `False` | Add an `"explain"` trace describing how the query ran.                                              |
| `target_recall` | `float \| None`      | `None`  | Per-query recall/latency hint for the planner (e.g. `0.95`).                                        |
| `with_metadata` | `bool`               | `False` | Add a `"metadata"` list aligned with the returned ids.                                              |

Like `search`, the result is `{"ids": [...], "scores": [...]}`, plus `"explain"` and `"metadata"` when requested. `ids` are ordered best-match first.

{% hint style="warning" %}
`search_text` needs an embedder; on a collection created with `embedder=None` it raises `RuntimeError`. Attach one at [creation](/working-with-data/create-a-collection.md) or reopen with `telys.open_collection(name, embedder=...)` so query and stored documents share one vector space.
{% endhint %}

## Basic query

```python
from telys import Telys
from telys.embedding import AlgentaMultigramEmbedder

telys = Telys("telys-store")
# "memories" was created with filter_columns=("scope", "topic"), so both keys
# come back in each hit's metadata under with_metadata=True.
memories = telys.open_collection("memories", embedder=AlgentaMultigramEmbedder())

result = memories.search_text("how do cells produce energy?", top_k=5, with_metadata=True)
```

```python
{
    "ids": ["bio-1", "bio-2", "bio-3"],
    "scores": [0.78, 0.66, 0.31],
    "metadata": [
        {"scope": "user:42", "topic": "biology"},
        {"scope": "user:42", "topic": "biology"},
        {"scope": "user:42", "topic": "biology"},
    ],
}
```

## Filter and tune per query

```python
from telys import Eq

result = memories.search_text(
    "energy",
    top_k=5,
    where=Eq("scope", "user:42"),
    target_recall=0.95,
    explain=True,
)
result["explain"]        # trace of how the query was executed
```

## Expected result

You pass a string and get parallel `ids` and `scores`, best-match first, plus an aligned `metadata` list with `with_metadata=True`. No manual embedding step is involved:

```python
>>> res = memories.search_text("mitochondria", top_k=2, with_metadata=True)
>>> res["ids"]
['bio-1', 'bio-2']
>>> res["scores"][0] >= res["scores"][1]
True
>>> res["metadata"][0]
{'scope': 'user:42', 'topic': 'biology'}
```

## Next steps

* [Filter results](/working-with-data/filter-results.md) — narrow a text search with `Eq` or a single-key dict.
* [Search by vector](/working-with-data/search-by-vector.md) — the raw-vector query path when you embed the query yourself.
* [Lexical vs dense embeddings](/understand-telys/lexical-vs-dense.md) — what "text match" means for the lexical embedders.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.telys.ai/working-with-data/search-by-text.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
