Create RAG API with PGVector
Overview
This is part of a series of articles about building RAG applications.
- Create and Store Vectors in PGVector
- Create RAG API with PGVector
BladePipe can automatically generate a chat service based on embeddings, named RagApi. It is compatible with the OpenAI interface, and the creation process doesn't use any code. This article dives into how to create a RagApi.
Why BladePipe?
Compared with the traditional manual deployment of RAG architecture, the RagApi service provided by BladePipe has the following unique advantages:
- RAG Built with Two DataJobs: text embedding + API building
- No Code: The custom configuration can be done in a few clicks. Even non-developers can finish RAG service building.
- Modifiable Parameters: It allows to set core parameters such as Top-K value, threshold for matching, prompt template, LLM temperature, etc.
- Support for Diverse LLMs and Platforms: It supports mainstream LLMs such as Alibaba Cloud DashScope, OpenAI and DeepSeek, and API platforms.
- Compatibility with OpenAI Interface: It can directly connect to existing Chat applications or toolchain without additional adaptation.
- Local Deployment: It supports local deployment of LLMs (such as DeepSeek) and APIs with Ollama to prevent internal data breach in organizations.
Flow Chart of RagApi Building
To build a RAG API with BladePipe, two DataJobs needs to be created. This article mainly talks about DataJob 2 (RAG API Building).

DataJob 1: File Embedding (File → PGVector)
For more details, please refer to Create and Store Embeddings in PGVector.
DataJob 2: RAG API Building (PGVector → RagApi)
-
Query Embedding and Retrieval Users enter their queries at a Chat interface. BladePipe uses the same embedding model to get the query embedding, and retrieves the most relevant chunks stored in the vector database.
-
Create Prompt
BladePipe constructs a complete context based on the configured Prompt template, combined with users' queries and search results. -
Chat Model Reasoning
The created Prompt is fed into the configured Chat model (such asqwq-plus,gpt-4o, etc.) to generate the final answer. The interface is an OpenAI format interface, which can be directly connected to the applications.
Supported LLMs
BladePipe uses the Chat model, together with the context obtained from the vector queries, to reason about the API request. Currently, the supported Chat models are as follows:
| Platform | Model |
|---|---|
| DashScope | qwq-plus qwq-plus |
| DeepSeek | deepseek-chat deepseek-chat |
| OpenAI | gpt-4o o1 o1-mini o3-mini ... |
Procedure
Next, we will demonstrate how to complete the second task: creating a RagApi service based on embeddings stored in the vector database.
Before start, make sure that you have finished text embedding. For more information, please refer to Create and Store Embeddings in PGVector.
The demonstration will be shown in an environment with:
- Vector database: PostgreSQL (with embeddings stored)
- Target service: RagApi deployed locally (to offer API for chatting)
- Embedding model: OpenAI text-embedding-3-large
- Chat model: OpenAI GPT-4o