llama-index vector_stores postgres integration
Project description
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 searchHYBRID- Combines dense and sparse retrievalSPARSE- BM25-based text searchTEXT_SEARCH- Full-text searchMMR- 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 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_vector_stores_postgres-0.8.1.tar.gz.
File metadata
- Download URL: llama_index_vector_stores_postgres-0.8.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f72f16f0a8776b610b44625b5fcab55a5977ce2fa5a7d3b162306a10d9b4e8
|
|
| MD5 |
0264f74db7ca7ddda6b0cb1dcc955e31
|
|
| BLAKE2b-256 |
5d88e89e75d7bd90b870e091157245c65ff89edddf5b6bedae83dbec4bdee28a
|
File details
Details for the file llama_index_vector_stores_postgres-0.8.1-py3-none-any.whl.
File metadata
- Download URL: llama_index_vector_stores_postgres-0.8.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
832a79f2276b51cbb249e34cdb27911b2369c1b9a29e9d39359879bfe789b196
|
|
| MD5 |
ca82a054457f9ac86ee5a91afbb77bb9
|
|
| BLAKE2b-256 |
5d60e2b938d79cd7d0c4e58f33d1c62e5d1edc2b9a4ac8c4f7e613dd7c4e17a1
|