# Semantic search over document chunks

Operation ID: `graph.vectorSearchDocuments`

Rank document chunks by semantic similarity to a natural-language query. The query is embedded server-side with the same model the collection was loaded with and matched by cosine similarity, so a question finds a document it shares no words with. Scope the search with collection (which corpus: consumer health topics or payer policies), then collection_group, source, language, network_id and tags within it. Searching the payer-policy collection requires payer_key: that corpus is partitioned by payer, so one search only ever returns one payer's policies.

## Public method

`vectorSearchDocuments`

Signature: `graph.vectorSearchDocuments(request)`

Return type: `Promise<VectorSearchResponse>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`POST /graph/vector/search`

## Path parameters

None.

## Query parameters

None.

## Body parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `body` | [`VectorSearchDocumentsRequest`](../models/VectorSearchDocumentsRequest.md) | Yes |  |  |  | No |  |

Request model: [`VectorSearchDocumentsRequest`](../models/VectorSearchDocumentsRequest.md)

## Request example

```json
{
  "collection": "string",
  "collection_group": "string",
  "language": "string",
  "network_id": "string",
  "payer_key": "string",
  "q": "string",
  "source": "string",
  "tags": [
    "string"
  ],
  "top_k": 10
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`VectorSearchResponse`](../models/VectorSearchResponse.md) | application/json | Ranked document chunks, closest first |

## Success response examples

### 200

```json
{
  "collection": "string",
  "count": 0,
  "embedding_model": "string",
  "filter": "string",
  "hits": [
    {
      "chunk_index": 0,
      "collection_group": "string",
      "doc_id": "string",
      "id": "string",
      "language": "string",
      "metadata": {},
      "network_id": "string",
      "payer_key": "string",
      "score": 0,
      "source": "string",
      "tags": [
        "string"
      ],
      "text": "string",
      "title": "string",
      "url": "string"
    }
  ],
  "query": "string"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`graph.ErrorResponse`](../models/graph.ErrorResponse.md) | application/json | The query was empty, the collection is not one this deployment serves, or a payer-partitioned collection was searched without a payer |
| `401` | [`graph.ErrorResponse`](../models/graph.ErrorResponse.md) | application/json | Authorization required — missing or invalid Bearer JWT |
| `500` | [`graph.ErrorResponse`](../models/graph.ErrorResponse.md) | application/json | Internal server error |
| `503` | [`graph.ErrorResponse`](../models/graph.ErrorResponse.md) | application/json | Vector search is not configured in this environment |

## Error examples

### 400 — The payer-policy collection was searched without naming a payer

```json
{
  "error": "payer_key is required when reading 'payer_policy_documents': it is partitioned by payer, so a read must name exactly one payer."
}
```

### 400 — The required 'q' field was empty

```json
{
  "error": "Field 'q' is required"
}
```

### 400 — The requested collection is not configured

```json
{
  "error": "Unknown collection 'nope'. Available: medical_documents, payer_policy_documents"
}
```

### 401 — Missing or invalid access token

```json
{
  "error": "Authorization required"
}
```

### 500 — Unexpected service failure (sanitized example)

```json
{
  "error": "Internal server error"
}
```

### 503 — No Milvus endpoint or embedding key is provisioned

```json
{
  "error": "Vector search is not configured"
}
```

## NodeJS / TypeScript implementation

```ts
import { HCSDK } from "@healthcloudai/hc-sdk";
import type { VectorSearchRequest } from "@healthcloudai/hc-sdk";
```

```ts
const request = {
  "collection": "string",
  "collection_group": "string",
  "language": "string",
  "network_id": "string",
  "payer_key": "string",
  "q": "string",
  "source": "string",
  "tags": [
    "string"
  ],
  "top_k": 10
};

const result = await graph.vectorSearchDocuments(request);
```

## cURL

```bash
curl -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"collection":"string","collection_group":"string","language":"string","network_id":"string","payer_key":"string","q":"string","source":"string","tags":["string"],"top_k":10}' \
  'https://dev-api-graph.health.cloud/graph/vector/search'
```

## Notes

None.

## Prepared Test Console scenario

No canonical scenario is currently associated.

## Real response

No approved real integration response is currently published. Unapproved candidates are never rendered as examples.
