pg_knowledge_graph
pg_knowledge_graph · Knowledge graph extension for PostgreSQL with graph algorithms and pgvector integration.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100845 | pg_knowledge_graph | pg_knowledge_graph | 0.1.0 | RAG | MIT | Rust |
PostgreSQL · 16, 17, 18
| Relationships | |
|---|---|
| Requires | vector |
Usage
Sources:
pg_knowledge_graph 0.1.0 stores entities and directed, weighted relationships in ordinary PostgreSQL tables and exposes traversal, ranking, component, vector, hybrid-search, RAG-context, and approximate quantized-search functions. It depends on vector and uses fixed 1536-dimensional embeddings in the upstream schema.
Core Workflow
Install pgvector first. The pgrx installation supplies the extension functions, but the repository’s own Docker initializer states that the graph tables must be created separately. Apply the cited schema SQL or create the two tables explicitly before inserting data.
Create the indexes from the official schema SQL, including the HNSW index on embedding, before using vector search at scale.
Function Groups
- Inspection:
kg_versionandkg_stats. - Traversal:
kg_bfs,kg_dfs, andkg_shortest_pathover directed edges. - Whole-graph algorithms:
kg_pagerank,kg_louvain,kg_connected_components, andkg_strongly_connected_components. - Retrieval:
kg_vector_search,kg_hybrid_search, andkg_get_context. - Approximate retrieval:
kg_quantized_searchwithint8,int4, orbinary, pluskg_quantize_info.
kg_hybrid_search combines vector and graph scores using caller-provided alpha and beta. kg_get_context returns an N-hop neighborhood for retrieval-augmented generation; it does not call an embedding or language-model service.
Operational Boundaries
The Rust functions query kg_entities and kg_relations through SPI and load graph or embedding data into the calling backend for several algorithms. PageRank, component detection, community detection, and quantized search are recomputed on demand rather than maintained incrementally. Benchmark memory, execution time, and statement timeouts on realistic graph sizes.
The functions use unqualified table names, so keep the official tables in the expected search path and prevent untrusted users from substituting look-alike relations. The extension is superuser-only, untrusted, and non-relocatable according to its control file.
Quantized similarity is approximate. The README’s compression and recall figures are project measurements, not correctness guarantees; evaluate recall using your embeddings. Version 0.1.0 declares PostgreSQL 16, 17, and 18 build features and should be treated as an early release until independently load- and failure-tested.