Skip to content

RAG Stores

The RAG (Retrieval-Augmented Generation) Stores page lets you create, manage and populate document collections that your AI agents use for grounding. Agents answer from the content you provide instead of relying only on their general knowledge.

Stores are backed by PostgreSQL with the pgvector extension. Uploaded files are converted to text, split into overlapping chunks, embedded with the store's embedding model and written to a store_chunks table. At chat time the agent embeds the user's question with the same model, retrieves the closest chunks and adds them to the prompt. No Google Cloud project, bucket or Vertex AI RAG corpus is required any more, and retrieval works with every LLM provider (Google, OpenAI, Anthropic, Ollama, ...).

RAG Stores

Prerequisites

  1. A PostgreSQL database with pgvector. Either the PinionAI platform database or any other PostgreSQL 12+ server with the vector extension available (pgvector 0.5 or newer for HNSW indexes). The Studio runs CREATE EXTENSION IF NOT EXISTS vector, creates the store_chunks table and the per-store index automatically; the same DDL is in db/pgvector_store_chunks.sql if you prefer to run it yourself. On Cloud SQL run the extension creation as the postgres user (it has the cloudsqlsuperuser role).
  2. An embedding model on the Models page tagged with the embedding capability (see below).
  3. Optionally a Database connector (Connectors page, type Database) when the chunks should live outside the platform database. The connector's Database Name is the database, Host the server, Username/Password the credentials. The same connector is used at chat time by the PinionAI API to run the retrieval query.

Embedding models

Create one model per embedding model you want to use (Models page -> Capabilities -> embedding):

Provider Model value Dimensions Notes
ollama nomic-embed-text 768 Endpoint = your Ollama host (port 11434 is added automatically). Also bge-m3 (1024), all-minilm (384).
openai text-embedding-3-small 1536 API key via an API Key connector or OPENAI_API_KEY.
openai text-embedding-3-large 3072 -> 1536 Reduced automatically (see dimensions).
google gemini-embedding-001 3072 -> 1536 API key via connector or GEMINI_API_KEY; Vertex AI with GCP_PROJECT/GCP_REGION. text-embedding-005 is 768.
openai-compatible, vllm any model dependent Any server exposing /v1/embeddings (vLLM, LM Studio, ...).

Set {"dimensions": 768} in the model's Model Config JSON to pin the vector size. pgvector indexes support at most 2000 dimensions; a model that natively produces more is reduced to 1536 (OpenAI and Google reduce server side, other models are truncated and re-normalised, which only works for Matryoshka-trained models).

Adding a New RAG Store

Expand New Store and fill out the form.

  • Store Name: unique, descriptive name (e.g. "Product Manuals"). Cannot be changed after creation.
  • Status: toggles the store on or off for all associated agents.
  • Agent(s): agents that can use this store. Several agents can share a store.
  • Description: what the store contains.
  • Store Connector (Database): the PostgreSQL database that holds this store's chunks. Leave blank to use the PinionAI platform database. Cannot be changed after creation.
  • Embedding Model: a model with the embedding capability. Cannot be changed after creation.
  • Embedding Dimensions: 0 detects the size automatically (model config dimensions, else the model's native size). The Studio embeds a probe text when the store is created, which also validates the model credentials.
  • Chunk Size / Chunk Overlap (characters): how documents are split. Defaults 1024 / 256. Editable later for new uploads.
  • Top K: maximum number of chunks retrieved per question.
  • Distance Threshold: maximum cosine distance (0-1) for a chunk to be returned. Lower is stricter.
  • Hybrid Search: fuse vector similarity with PostgreSQL full-text search (reciprocal rank fusion). Helps with exact terms such as product codes or error numbers.

Creating the store writes the stores row, enables pgvector in the target database if needed and creates the store's HNSW index (idx_sc_hnsw_<store uid>).

Managing Stores and Files

Each store appears in a list. Expand a store to see its configuration, chunk count and files.

  • Edit (:material/edit:): status, agents, description, chunk size/overlap, hybrid search, top K, threshold and the sync source (see Synced stores).
  • Export (:material/file_download:) / Import RAG Store: the store configuration as JSON (documents are not included; upload them again after importing).
  • Delete (:material/delete:): removes the chunks and index from the store database, then the store and its file records from the PinionAI database.

Managing Files

Inside the store's expander:

  • File Uploader: drag and drop one or more files. Supported types: pdf, docx, txt, md, csv, tsv, json, xml, html, log, rst, yaml.
  • Upload Process: for each file the Studio (1) creates a store_files record with status processing, (2) extracts the text, (3) skips the file if an identical document is already in the store (skipped), (4) splits it into chunks, (5) embeds the chunks in batches and (6) writes them to store_chunks. The record ends as ready with its chunk count, or error with the reason. The extracted text is kept so the file can be re-indexed.
  • Re-index: re-chunks and re-embeds a file from its stored text (after changing chunk size/overlap, after an error, or for stores copied by onboarding which arrive as needs_reindex).
  • Test search: runs a question through the same embedding + retrieval path the agent uses and shows the matching chunks with their cosine distance (and RRF score for hybrid stores).
  • Delete: removes the file's chunks from the store database and its record.

Using a Store in an Agent

  1. On the Tools page create a tool whose Tool List contains Tool(retrieval = RagStore(<store name>)) (or simply RagStore(<store name>)). A bare RagStore uses the first store assigned to the agent.
  2. Add that tool to a prompt on the Prompts page.
  3. When the prompt runs, the runtime embeds the user's input, calls the PinionAI API POST /retrieve and places the chunks in the variable rag_context (rag_chunks lists them with file name, index, distance and metadata, without the text). If the prompt body does not reference {{var.rag_context}} the text is appended automatically as Retrieved Knowledge. Retrieval errors are logged and stored in rag_error; the prompt still runs.
  4. The runtime must be pinionai 0.4.8 or newer: older packages do not know the RagStore tool and ignore it without an error, so an agent that answers without retrieved knowledge is usually running an old SDK.

Synced stores (documents from an API)

A store can take its documents from an API instead of (or as well as) uploads, for content that changes on its own schedule: a product catalogue, an inventory, a knowledge base kept in another system.

  1. On the APIs page create an active GET API that returns the store's full document set. Put any credential in its Header JSON (connectors are not used by the sync). The answer must be:
{"documents": [
  {"id": "sku-1042", "name": "sku-1042.md", "text": "# Trail Runner 2 ...", "metadata": {"sku": "sku-1042", "price": 129}}
]}
  • id (required): the source's stable key for the document.
  • name (optional, default <id>.md): the file name shown on the Stores page and returned with retrieved chunks (var.rag_chunks).
  • text (required): the document. A document no longer than the store's chunk size stays one chunk.
  • metadata (optional object): stored on every chunk and returned with it.

Entries without an id or text, or with a duplicate id or name, are skipped and counted as errors. 2. Edit the store, choose the API under Sync source -> Sync API, set Sync every (minutes) (at least 5) and switch on Scheduled sync. 3. In the store's expander use Preview sync (fetches and diffs, writes nothing) and Sync now.

Each sync compares the snapshot with the store: new documents and documents whose text, metadata or name changed are embedded and written, unchanged ones are skipped, and synced documents the API no longer returns are removed. Uploaded files are never removed by a sync; an uploaded file with the same name as a document is taken over by it. If the API returns no documents while the store has synced documents, the run fails and nothing is deleted. Documents that fail to embed or write keep their previous chunks and are retried on the next run.

Scheduled syncs are run by python -m tools.sync_stores inside the Studio container, started every 5 minutes by the host timer in deploy/systemd/ (see its README); each run only syncs the stores whose interval has elapsed. Only one sync of a store runs at a time. Every run is recorded in store_sync_runs (kept 30 days) and listed under Sync runs in the store's expander. By hand:

docker exec pinionai-studio-container python -m tools.sync_stores                          # every store that is due
docker exec pinionai-studio-container python -m tools.sync_stores --store <uid> --dry-run  # preview one store
docker exec pinionai-studio-container python -m tools.sync_stores --store <uid> --rebuild  # re-embed everything

Imported and onboarding-cloned stores keep their sync API but start with Scheduled sync off.

Stores with more than 50 files show a status summary and a name filter on the Stores page instead of every row.

Database tables

  • stores (platform database): configuration incl. embedding_model, store_model_provider, embedding_dimensions, chunk_size, chunk_overlap, store_hybrid_search, store_connector, top_k, vector_distance_threshold, and for synced stores store_sync_api, store_sync_interval_minutes, store_sync_status.
  • store_files (platform database): one row per upload or synced document with file_status, chunk_count, extracted_text, content_hash, error_message and, for synced documents, source_document_id.
  • store_sync_runs (platform database): one row per sync with its trigger, status, counts and message.
  • store_chunks (store database): store_uid_fk, store_file_uid_fk, chunk_index, content, metadata, embedding_dim, embedding (pgvector) and a generated fts column for hybrid search. It has no foreign keys to the platform tables because it may live in another database; the Studio deletes chunks explicitly.

Stores created with the former Google Vertex AI RAG backend still appear in the list but have no embedding configuration; delete them, create a new store and upload the documents again.