2025-10-25 14:50:14 -03:00
# Semantic Search
2025-10-25 15:59:06 -03:00
2025-10-25 20:28:40 -03:00
Semantic search enables the bot to retrieve information based on meaning rather than exact keyword matches. It leverages the vector embeddings stored in VectorDB.
2025-10-25 15:59:06 -03:00
## How It Works
1. **Query Embedding** – The user’ s query string is converted into a dense vector using the same embedding model as the documents.
2025-10-25 20:28:40 -03:00
2. **Nearest‑ Neighbor Search** – VectorDB returns the top‑ k vectors that are closest to the query vector.
2025-10-25 15:59:06 -03:00
3. **Result Formatting** – The matching document chunks are concatenated and passed to the LLM as context for the final response.
## Using the `FIND` Keyword
```basic
2025-11-21 23:23:53 -03:00
USE_KB "company-policies"
2025-10-25 15:59:06 -03:00
FIND "how many vacation days do I have?" INTO RESULT
TALK RESULT
```
2025-11-21 23:23:53 -03:00
- `USE_KB` adds the collection to the session.
2025-10-25 15:59:06 -03:00
- `FIND` performs the semantic search.
- `RESULT` receives the best matching snippet.
## Parameters
- **k** – Number of results to return (default 3). Can be overridden with `FIND "query" LIMIT 5 INTO RESULT` .
- **filter** – Optional metadata filter, e.g., `FILTER source="policy.pdf"` .
## Best Practices
- Keep the query concise (1‑ 2 sentences) for optimal embedding quality.
- Use `FORMAT` to clean up the result before sending to the user.
- Combine with `GET_BOT_MEMORY` to store frequently accessed answers.
## Performance
2025-10-25 20:28:40 -03:00
Semantic search latency is typically < 100 ms for collections under 50 k vectors . Larger collections may require tuning VectorDB ’ s HNSW parameters .