riff-kg-kit
PyPI-first Python library for staged knowledge-graph ingestion and agent-approved commits, designed to plug into Riff apps (FastAPI + Postgres + pgvector).
Status
0.7.1 — Extraction durability. run_extraction_for_signal commits staged proposals per segment (when not inside a caller transaction), marks failed runs with error_message, and keeps proposals from completed segments if a later segment errors or times out. 0.7.0 added hybrid reranking, graph-hop retrieval, and pack_context helpers.
Install
pip install riff-kg-kit
Editable (local dev):
pip install -e ".[dev,yaml]"
Quick use
from riff_kg import KgConfig
cfg = KgConfig.model_validate_json('{"embedding_dimension": 768}')
assert cfg.embedding_dimension == 768
Chunking strategy
By default, chunking uses fixed character windows. You can opt into boundary-aware chunking that prefers paragraph/sentence/whitespace splits:
from riff_kg import KgConfig
cfg = KgConfig(
chunking_strategy="semantic", # "char" (default) or "semantic"
chunk_if_longer_than_chars=12000,
chunk_max_chars=8000,
chunk_overlap_chars=400,
)
Roadmap (summary)
- Migrations + core tables (
signal,signal_segment,staged_proposal, …) - Normalize → segment → embed
- Extract → stage (LLM proposals only)
- Approve → commit (validated canonical graph)
- Search / pack-context / retrieval (implemented:
riff_kg.search)
Retrieval (Phase 5)
from riff_kg import KgConfig
from riff_kg.search import pack_context, search_segments_vector
# After migrations and ingest with embeddings, pass a query embedding
# (same dimension as KgConfig.embedding_dimension, e.g. 768):
# hits = await search_segments_vector(conn, cfg, query_vec, scope_id="my_scope")
# text = pack_context(hits)
Hybrid rerank and graph hops
from riff_kg.search import graph_hop_subgraph, search_segments_hybrid
# Hybrid search with Reciprocal Rank Fusion (default)
# hits = await search_segments_hybrid(conn, cfg, query_embedding=qvec, fts_query="topic")
# Graph neighborhood around a committed entity
# nodes, edges = await graph_hop_subgraph(conn, root_entity_id=entity_id, max_hops=2, scope_id="my_scope")
Publishing checklist
- Bump version in
pyproject.tomlandsrc/riff_kg/__init__.py. - Update
CHANGELOG.mdand README status/examples. - Run
python -m ruff check src testsandpython -m pytest tests -q. - Build distributions:
python -m build. - Upload to TestPyPI first, verify install, then publish to PyPI.
License
Apache-2.0 — see LICENSE.
Metadata
Release files for riff-kg-kit 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| riff_kg_kit-0.8.0.tar.gz | 22.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| riff_kg_kit-0.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.1 kB
Release files / riff_kg_kit-0.8.0.tar.gz
| Download URL | riff_kg_kit-0.8.0.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6aad4265fd0219a579256d33ea571c609769745b8457ec995926f2e5d80a7d6a
|
|
BLAKE2b-256 checksum How to use checksums |
d0935958b2e4fb77391b5551c363566d0502f7138b040066793f83546c1b5e15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / riff_kg_kit-0.8.0-py3-none-any.whl
| Download URL | riff_kg_kit-0.8.0-py3-none-any.whl |
|---|---|
| Size | 22.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c56214400c10748fd7d77d3f2c2e4bebcfe3da7bec24c1881f69c2fd138b74a
|
|
BLAKE2b-256 checksum How to use checksums |
fafd5745941d5338a30428b050624134b715e08c061ad465e70570a4f6f776e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|