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

# Search and ask

> Lexical, vector, and hybrid retrieval from Rust

memvid-core exposes structured request/response types for retrieval:

```rust theme={null}
use memvid_core::{AclContext, AclEnforcementMode, AskMode, AskRequest, Memvid, SearchRequest};

let mut mv = Memvid::open_read_only("notes.mv2")?;

let search = mv.search(SearchRequest {
    query: "Stardust".into(),
    top_k: 5,
    snippet_chars: 200,
    uri: None,
    scope: None,
    cursor: None,
    #[cfg(feature = "temporal_track")]
    temporal: None,
    as_of_frame: None,
    as_of_ts: None,
    no_sketch: false,
    acl_context: Some(AclContext {
        tenant_id: Some("tenant-123".into()),
        subject_id: Some("matt".into()),
        roles: vec!["finance".into()],
        group_ids: vec![],
    }),
    acl_enforcement_mode: AclEnforcementMode::Enforce,
})?;

let context_only = mv.ask(
    AskRequest {
        question: "What powers the deterministic index?".into(),
        top_k: 5,
        snippet_chars: 200,
        uri: None,
        scope: None,
        cursor: None,
        start: None,
        end: None,
        #[cfg(feature = "temporal_track")]
        temporal: None,
        context_only: true,
        mode: AskMode::Lex,
        as_of_frame: None,
        as_of_ts: None,
        adaptive: None,
        acl_context: Some(AclContext {
            tenant_id: Some("tenant-123".into()),
            subject_id: Some("matt".into()),
            roles: vec!["finance".into()],
            group_ids: vec![],
        }),
        acl_enforcement_mode: AclEnforcementMode::Enforce,
    },
    None,
)?;
```

* `Memvid::search(SearchRequest)` performs lexical retrieval and returns a `SearchResponse` with the selected `engine`
* `Memvid::ask(AskRequest, Option<&impl VecEmbedder>)` runs retrieval + optional synthesis (set `context_only: true` to only fetch context)
* `Memvid::vec_search_with_embedding(...)` performs pure vector search when you already have a query embedding (and validates dimensions)

`search()` and `ask()` require the `lex` crate feature (enabled by default). For semantic-only or hybrid ranking, pass a `VecEmbedder` implementation (or use `vec_search_with_embedding` with a precomputed query vector).

## Permission-Aware Retrieval (ACL)

Use `acl_context` + `acl_enforcement_mode` to enforce tenant isolation and RBAC at retrieval time.

See [Permission-Aware Retrieval (ACL)](/concepts/permission-aware-retrieval).

> Tip: If you want to plug in an LLM, use `AskResponse.retrieval.context` as the prompt context and keep `context_only: true` in the core call.
