Skip to main content

LlamaIndex Vector_Stores Integration: Postgres

This integration allows you to use PostgreSQL with the pgvector extension as a vector store for LlamaIndex.

Installation

pip install llama-index-vector-stores-postgres

Usage

Basic Setup

from llama_index.vector_stores.postgres import PGVectorStore

vector_store = PGVectorStore.from_params(
    database="your_database",
    host="localhost",
    password="your_password",
    port="5432",
    user="your_user",
    table_name="your_table",
    embed_dim=1536,  # OpenAI embedding dimension
)

Query Modes

The PGVectorStore supports multiple query modes:

  • DEFAULT - Standard similarity search
  • HYBRID - Combines dense and sparse retrieval
  • SPARSE - BM25-based text search
  • TEXT_SEARCH - Full-text search
  • MMR - Maximal Marginal Relevance for diverse results

MMR (Maximal Marginal Relevance) Queries

MMR balances relevance and diversity in search results. Use it when you want results that are both relevant to the query and diverse from each other.

from llama_index.core import VectorStoreIndex

# Create index with PGVectorStore
index = VectorStoreIndex.from_vector_store(vector_store)

# Query engine with MMR
query_engine = index.as_query_engine(
    vector_store_query_mode="mmr",
    similarity_top_k=5,
    vector_store_kwargs={
        "mmr_threshold": 0.5,  # 0=max diversity, 1=max similarity
    },
)
response = query_engine.query("Your question here")

# Retriever with MMR
retriever = index.as_retriever(
    vector_store_query_mode="mmr",
    similarity_top_k=5,
    vector_store_kwargs={
        "mmr_threshold": 0.3,  # Lower = more diverse results
        "mmr_prefetch_factor": 4.0,  # Prefetch multiplier (default: 4.0)
    },
)
nodes = retriever.retrieve("Your query here")

MMR Parameters

Parameter Description Default
mmr_threshold Balance between relevance (1.0) and diversity (0.0) 0.5
mmr_prefetch_factor Multiplier for candidate pool size 4.0
mmr_prefetch_k Exact candidate pool size (overrides factor) None

Metadata

Release files for llama-index-vector-stores-postgres 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-vector-stores-postgres 0.10.0
File Size Uploaded Provenance Actions
llama_index_vector_stores_postgres-0.10.0.tar.gz 14.5 kB Without provenance Details for llama_index_vector_stores_postgres-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-vector-stores-postgres 0.10.0
File Interpreter ABI Platform Actions
llama_index_vector_stores_postgres-0.10.0-py3-none-any.whl Python 3 none any Details for llama_index_vector_stores_postgres-0.10.0-py3-none-any.whl

Total release size: 28.9 kB

Release files / llama_index_vector_stores_postgres-0.10.0.tar.gz

Download URL llama_index_vector_stores_postgres-0.10.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e2f3402c80d0d843b89ec3fd6fac8c13bd3a1ecc9f872037678ce0af8db684e2
BLAKE2b-256 checksum
How to use checksums
73de1e6b71e80a0500b9177ebf353f55d8a5f94749bac8eea4d39a4e89c11ca0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_vector_stores_postgres-0.10.0-py3-none-any.whl

Download URL llama_index_vector_stores_postgres-0.10.0-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d038e9ca26f8766b6c9dfd0318fe8075c9aa7e9d9ae3f306d7cbae0c62580d4
BLAKE2b-256 checksum
How to use checksums
7a65a3e94ee6fa4d78cf7c70f08d8ecd228b045b83b5a1bcb2ebfb814fc35122
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-vector-stores-postgres 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page