Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

PgvectorKeywordRetriever

Retrieve documents from a PgvectorDocumentStore using keyword-based full-text search.

Key Features​

  • Full-text search using PostgreSQL's ts_rank_cd ranking function.
  • Ranks documents based on query term frequency, proximity, and position.
  • Configurable number of results with top_k.
  • Supports metadata filtering to narrow down the search space.
  • Configurable filter policy (replace or merge) for runtime filters.

Configuration​

  1. Drag the PgvectorKeywordRetriever component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    • Configure the PgvectorDocumentStore with your PostgreSQL connection string.
    • Set top_k to control the maximum number of documents to retrieve.
  4. Go to the Advanced tab to configure filter_policy.

Connections​

PgvectorKeywordRetriever receives the user query as a text string, typically from the Input component. It sends retrieved documents to downstream components such as PromptBuilder or a ranker.

Source Code​

To check this component's source code, open keyword_retriever.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

PgvectorKeywordRetriever:
type: haystack_integrations.components.retrievers.pgvector.keyword_retriever.PgvectorKeywordRetriever
init_parameters:
top_k: 10
document_store:
type: haystack_integrations.document_stores.pgvector.document_store.PgvectorDocumentStore
init_parameters:
connection_string:
type: env_var
env_vars:
- PG_CONN_STR
strict: false
table_name: haystack_documents
language: english

Using the Component in a Pipeline​

# haystack-pipeline
components:
PgvectorKeywordRetriever:
type: haystack_integrations.components.retrievers.pgvector.keyword_retriever.PgvectorKeywordRetriever
init_parameters:
top_k: 10
document_store:
type: haystack_integrations.document_stores.pgvector.document_store.PgvectorDocumentStore
init_parameters:
connection_string:
type: env_var
env_vars:
- PG_CONN_STR
strict: false
table_name: haystack_documents

connections: []

max_runs_per_component: 100

metadata: {}

inputs:
query:
- PgvectorKeywordRetriever.query

outputs:
documents: PgvectorKeywordRetriever.documents

Parameters​

Inputs​

ParameterTypeDescription
querystrThe text query to search for.
filtersOptional[Dict[str, Any]]Filters to apply to the search results.
top_kOptional[int]The maximum number of documents to return.

Outputs​

ParameterTypeDescription
documentsList[Document]The retrieved documents.

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
document_storePgvectorDocumentStoreAn instance of PgvectorDocumentStore.
filtersOptional[Dict[str, Any]]NoneDefault filters applied when running the retriever.
top_kint10The maximum number of documents to retrieve.
filter_policyUnion[str, FilterPolicy]FilterPolicy.REPLACEPolicy for how runtime filters are applied relative to init-time filters.

Run Method Parameters​

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
querystrThe text query to search for.
filtersOptional[Dict[str, Any]]NoneFilters to apply at query time.
top_kOptional[int]NoneOverride the init-time top_k setting.