# Knowledge Base

Knowledge Base components connect the flow to semantic search indexes for retrieval-augmented generation.

---

## Knowledge Retrieval

Retrieves relevant chunks from a knowledge base using semantic search. Connects to knowledge bases configured in the Foundry and can search across multiple bases in one run.

**Use in a flow**

1. Add a **Knowledge Retrieval** node to the canvas.
2. Select one or more **Knowledge Bases** from the workspace dropdown (refresh to load the latest list).
3. Provide a **Search Query** (wire from **Input**, **Prompt**, or another upstream component).
4. Connect **Search Results** or **DataFrame** to downstream steps (for example, **Prompt** or an Agent).

```
Input (Message) ──► Knowledge Retrieval ──► Prompt ──► Agent
```

Results from all selected knowledge bases are aggregated and sorted by relevance score.

**Parameters**

| Parameter | Default | Hidden | Description |
| --- | --- | --- | --- |
| Knowledge Bases | — | No | One or more knowledge bases to search. Refresh to reload options. Required. |
| Search Query | — | No | The question or text to search for. Required. |
| Fallback Knowledge Base | — | Yes | Knowledge base used when the user lacks access to a selected primary KB. Required. |
| Top K Results | 4 | Yes | Maximum number of results to return per knowledge base. |
| Search Type | similarity | Yes | `similarity` (vector search) or `hybrid_search` (combines keyword and vector search). |
| Search Score Threshold | 0.0 | Yes | Minimum similarity score (0.0–1.0). Results below this threshold are excluded. |
| Search Metadata | — | Yes | JSON metadata filters to narrow results (e.g., `{"department": "HR"}`). |
| Use SSL | true | Yes | Use SSL when connecting to OpenSearch. |
| Verify Certificates | false | Yes | Verify SSL certificates for the OpenSearch connection. |
| Save Output as Variable | false | Yes | Store this component’s output as a named flow variable. |
| Variable Name | — | No | Name for the flow state variable when **Save Output as Variable** is enabled. |

**Outputs**

| Output | Description |
| --- | --- |
| Search Results | Matching document chunks as Data objects (text and metadata). |
| DataFrame | Search results as a table. |

**Limitations**

- **Foundry configuration** — Knowledge bases must exist in the workspace and be accessible to the current user.
- **Search query required** — **Hybrid search** requires a non-empty query.
- **Multi-KB search** — **Top K** applies per knowledge base, not globally across all selected bases.
- **KB types** — Supports in-house and Bedrock knowledge bases. Bedrock backends use the Bedrock Retrieve API internally.

---

## OpenSearch

Queries an Amazon OpenSearch index directly with configurable search type, scoring threshold, and hybrid search support.

**Use in a flow**

1. Add an **OpenSearch** node to the canvas.
2. Connect an **Embedding** model component.
3. Select an **Index Name** (knowledge base index).
4. Provide a **Search Query**, or connect **Ingest Data** to add documents before searching.
5. Connect **Search Results** or **DataFrame** downstream.

```
Embeddings ──► OpenSearch ◄── Split Text (Ingest Data)
Input ──► OpenSearch (Search Query) ──► Prompt ──► Agent
```

**Parameters — Connections and search**

| Parameter | Default | Hidden | Description |
| --- | --- | --- | --- |
| Index Name | — | No | OpenSearch index to query. Select from configured knowledge base indexes. Required. |
| Embedding | — | No | Embedding model used to vectorize the search query. Required. |
| Ingest Data | — | No | Data or DataFrame to add to the index before searching. |
| Search Query | — | No | Query text for similarity search. |
| Search Type | similarity | Yes | `similarity`, `similarity_score_threshold`, or `mmr` (max marginal relevance). |
| Number of Results | 4 | Yes | Maximum number of results to return. |
| Search Score Threshold | 0.0 | Yes | Minimum score when **Search Type** is `similarity_score_threshold`. |
| Hybrid Search Query | — | Yes | Custom OpenSearch hybrid query in JSON format. When set, overrides standard search. |
| Search Metadata | — | Yes | JSON metadata filters to narrow results. |

**Parameters — Connection settings**

| Parameter | Default | Hidden | Description |
| --- | --- | --- | --- |
| OpenSearch URL | — | Yes | Auto-configured from environment based on index type. |
| Username | admin | Yes | OpenSearch username. |
| Use SSL | true | Yes | Use SSL for the OpenSearch connection. |
| Verify Certificates | false | Yes | Verify SSL certificates. |
| Cache Vector Store | true | Yes | Reuse the same vector store instance within a single flow run. |
| Enable Retry | false | Yes | Retry failed search requests. |
| Max Retries | 3 | Yes | Maximum retry attempts. |

**Outputs**

| Output | Description |
| --- | --- |
| Search Results | Matching document chunks as Data objects. |
| DataFrame | Search results as a table. |
| Ingested Data | Documents that were ingested into the index during this run. |

**Limitations**

- **Embedding required** — A connected Embeddings component is required for vector search.
- **Index selection** — **Index Name** must match a configured knowledge base index in the workspace.
- **Hybrid search** — **Hybrid Search Query** must be valid OpenSearch JSON; invalid JSON causes an error.
- **Direct OpenSearch** — Connection details are resolved from platform configuration based on the selected index type.
