> ## Documentation Index
> Fetch the complete documentation index at: https://velt-mintlify-e6426361.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Search Knowledge Base

> Run a workspace-scoped semantic vector search over ingested knowledge base content in Velt Memory v2 to retrieve relevant chunks and citations.

Use this API to run a semantic vector search over the **content of your ingested knowledge base**: the chunked, embedded text extracted from the files you've ingested. This is distinct from searching learned judgments (which [`search` and `ask`](/ai/memory/setup) read over). The endpoint is workspace-scoped.

# Endpoint

`POST https://api.velt.dev/v2/memory/knowledge/search`

# Headers

<ParamField header="x-velt-api-key" type="string" required>
  Your API key.
</ParamField>

<ParamField header="x-velt-auth-token" type="string" required>
  Your [Auth Token](/security/auth-tokens).
</ParamField>

# Body

#### Params

<ParamField body="data" type="object" required>
  <Expandable title="properties">
    <ParamField body="query" type="string" required>
      The natural-language search query. It is embedded and matched against your knowledge chunks by cosine nearest-neighbour.
    </ParamField>

    <ParamField body="sourceId" type="string | string[]">
      Restrict the search to one or more knowledge sources. A single id restricts to that source; an array of **2 to 30** ids fans out one prefiltered nearest-neighbour search per id and merges/re-ranks the combined results by distance. Omit to search the entire workspace knowledge base.
    </ParamField>

    <ParamField body="limit" type="integer">
      Maximum number of results to return.
    </ParamField>

    <Note>
      This endpoint is **workspace-scoped**. `organizationId` and `documentId` are not accepted; the strict schema rejects them rather than silently ignoring them. An unknown or cross-workspace `sourceId` returns empty results (never an error or a cross-tenant read). On embedding failure, the endpoint falls back to a recency query.
    </Note>
  </Expandable>
</ParamField>

## **Example Requests**

#### Search a single source

```JSON theme={null}
{
  "data": {
    "query": "citation policy",
    "sourceId": "src_9a8...",
    "limit": 10
  }
}
```

#### Search across multiple sources

```JSON theme={null}
{
  "data": {
    "query": "citation policy",
    "sourceId": ["src_9a8...", "src_2b1..."],
    "limit": 10
  }
}
```

#### Search the whole workspace knowledge base

```JSON theme={null}
{
  "data": {
    "query": "citation policy",
    "limit": 10
  }
}
```

# Response

Each result includes the matched `sourceId`, the chunk `text`, and a `score`: the cosine distance, where **lower is more relevant**. `recordsSearched` reports how many sources were queried.

#### Success Response

```JSON theme={null}
{
  "result": {
    "results": [
      {
        "sourceId": "src_9a8...",
        "text": "Always cite a peer-reviewed source...",
        "score": 0.18
      }
    ],
    "recordsSearched": 1
  }
}
```

#### Failure Response

```JSON theme={null}
{
  "error": {
    "message": "ERROR_MESSAGE",
    "status": "INVALID_ARGUMENT"
  }
}
```

<ResponseExample>
  ```js theme={null}
  {
    "result": {
      "results": [
        {
          "sourceId": "src_9a8...",
          "text": "Always cite a peer-reviewed source...",
          "score": 0.18
        }
      ],
      "recordsSearched": 1
    }
  }
  ```
</ResponseExample>
