PGVector
PGVector lets you store text or other data in a PostgreSQL database and then find the most similar items quickly. It works with embeddings, so you can search by meaning rather than exact words.
How it Works
When you add data, PGVector turns each piece of information into a numeric vector using the embedding model you provide. It then saves those vectors in a PostgreSQL table (called a collection).
When you search, it converts your query into a vector and looks for the closest vectors in the table, returning the original documents that match best. All of this happens inside your PostgreSQL database, so you don’t need any external services.
Operations
This component offers several operations that you can select based on what you need to do. You can only use one operation at a time:
- Add: Store new documents in the vector store.
- Search: Find documents that are most similar to a given query.
- Retriever: Create a retriever object that can be used later in a workflow to fetch relevant documents.
To use the component, first select the operation you need in the “Operation” field.
Inputs
This component requires a Postgres SQL credential.
- Configure a Postgres SQL credential in the Nappai credentials section, providing the server connection URL.
- Select that credential in the Credential field of this component.
Input Fields
The following fields are available to configure this component. Each field may be visible in different operations:
-
Embedding: The embedding model that turns text into vectors.
- Visible in: Add, Search, Retriever
-
Ingest Data: The documents you want to add to the vector store.
- Visible in: Add
-
Operation: Choose which operation to run (Add, Search, or Retriever).
- Visible in: Add, Search, Retriever
-
Table: The name of the PostgreSQL table (collection) where data will be stored or searched.
- Visible in: Add, Search, Retriever
-
Number of Results: How many documents to return when searching.
- Visible in: Add, Search, Retriever
-
Search Query: The text you want to search for. Leave empty to retrieve all documents.
- Visible in: Search
Outputs
- Retriever: A retriever object that can be used later in a workflow to fetch relevant documents.
- Results: The list of documents returned by a search operation.
- Vector Store: The underlying PGVector store object, useful if you need to pass it to other components.
Usage Example
Adding Documents
- Set Operation to Add.
- Provide an Embedding model.
- Drag your documents into Ingest Data.
- Specify the Table name (e.g.,
my_docs
). - Click Run. The component will store the documents in PostgreSQL.
Searching for Similar Documents
- Set Operation to Search.
- Provide the same Embedding model used for adding.
- Enter a Search Query (e.g., “machine learning trends”).
- Set Number of Results to 5.
- Click Run. The component returns the top 5 most similar documents in Results.
Related Components
- FAISS Vector Store – Stores vectors in memory for very fast local searches.
- Chroma Vector Store – A lightweight vector store that works with local or cloud storage.
- OpenAI Embeddings – Generates embeddings that can be used with any vector store.
Tips and Best Practices
- Use the same embedding model for both adding and searching to ensure consistent results.
- Keep the Table name short and descriptive; it becomes the PostgreSQL table name.
- If you need to update documents, run Add again with the same table; new vectors will overwrite old ones.
- For large datasets, consider batching the Ingest Data to avoid timeouts.
Security Considerations
- The component stores the PostgreSQL connection URL in a credential. Make sure the credential is only shared with trusted users.
- Do not expose the Credential field in public workflows.
- Keep your PostgreSQL database behind a firewall and use SSL/TLS for connections whenever possible.