> For the complete documentation index, see [llms.txt](https://karini-ai.gitbook.io/karini-ai-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://karini-ai.gitbook.io/karini-ai-documentation/recipes/knowledgebase-recipe/postgresql.md).

# PostgreSQL

The PostgreSQL Knowledge base allows you to use a PostgreSQL database with pgvector as a vector store for your AI workflows. This enables semantic search over your data stored in PostgreSQL, making it available as a retrieval source for agents, recipes, and copilots.

PostgreSQL can be used as a knowledgebase provider in two contexts:

1. **Recipe Knowledge Base Node** : As a vector database backend for the native knowledge base in your recipe workflows
2. **Agent Tool** : As a knowledgebase tool or dataset tool attached to Agent or Deep Agent nodes

### Prerequisites

Before configuring a PostgreSQL knowledgebase, ensure you have:

* A PostgreSQL instance (version 11+) with the **pgvector** extension installed and enabled.
* Network connectivity between the platform and your PostgreSQL host.
* A database user with read/write permissions on the target database.
* An embeddings model configured in the platform (used to generate vector embeddings for your data).

#### Configure PostgreSQL Credentials

Before creating a Knowledge Base recipe that uses **PostgreSQL** as the vector store provider, the PostgreSQL database must be prepared and the connection credentials must be configured at the organization level.

This setup enables the Karini AI platform to securely connect to PostgreSQL for document ingestion, embedding persistence, vector indexing, and similarity-based retrieval operations.

PostgreSQL credentials are configured from the **Organization** page under the **Vector Database Credentials** section by selecting **PostgreSQL Credentials**.

### Step 1 : Prepare the PostgreSQL Database

Before proceeding with recipe configuration, connect to the PostgreSQL database using a **superuser** account or a role with equivalent administrative privileges. For AWS RDS deployments, use a role with `rds_superuser` privileges.

Run the following SQL commands to enable vector support and create the Knowledge Base application role:

```
-- Enable the pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;

-- Create the Knowledge Base application role
CREATE ROLE karini_kb WITH LOGIN PASSWORD 'secure_password';

-- Grant database connection access
GRANT CONNECT ON DATABASE your_database TO karini_kb;

-- Grant schema usage and object creation privileges
GRANT USAGE, CREATE ON SCHEMA public TO karini_kb;

-- Grant full access to existing tables in the schema
GRANT ALL ON ALL TABLES IN SCHEMA public TO karini_kb;

-- Grant full access to future tables created in the schema
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT ALL ON TABLES TO karini_kb;
```

These permissions allow the Knowledge Base service to create and manage the required database objects, persist vector embeddings, create indexes, and execute retrieval queries during recipe processing.

### Step 2 : Configure PostgreSQL Credentials&#x20;

After the PostgreSQL database is prepared, configure the PostgreSQL connection details in the Karini AI platform at the organization level. These credentials are used by the platform to authenticate with PostgreSQL and execute Knowledge Base ingestion, embedding storage, indexing, and retrieval operations.

#### Navigation

1. Go to the **Organization** page.
2. Open the **Vector Database Credentials** section.
3. Select **PostgreSQL Credentials**.
4. Enter the required PostgreSQL connection details.
5. Save the configuration.

#### Configuration Fields

| Field             | Description                                                               |
| ----------------- | ------------------------------------------------------------------------- |
| **Host**          | PostgreSQL database host name or endpoint.                                |
| **Port**          | PostgreSQL service port. The default port is `5432`.                      |
| **Database Name** | Target PostgreSQL database used for Knowledge Base storage.               |
| **Schema**        | Target schema where Knowledge Base objects are created, such as `public`. |
| **Username**      | PostgreSQL role configured for Knowledge Base access.                     |
| **Password**      | Password associated with the configured PostgreSQL role.                  |

After saving the credentials, the PostgreSQL connection becomes available for Knowledge Base recipes that use **PostgreSQL** as the vector store provider.

Refer to the [**Knowledge base**](/karini-ai-documentation/recipes/knowledgebase-recipe.md) **recipe** section for recipe configuration.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://karini-ai.gitbook.io/karini-ai-documentation/recipes/knowledgebase-recipe/postgresql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
