Skip to main content

Opinionated knowledge-graph ingest, staged proposals, and retrieval for Riff (FastAPI) apps

Project description

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.0 — Retrieval+ updates. Adds hybrid reranking strategies and graph-hop retrieval helpers on top of vector/FTS segment search and pack_context.

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

Roadmap (summary)

  1. Migrations + core tables (signal, signal_segment, staged_proposal, …)
  2. Normalize → segment → embed
  3. Extract → stage (LLM proposals only)
  4. Approve → commit (validated canonical graph)
  5. 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

  1. Bump version in pyproject.toml and src/riff_kg/__init__.py.
  2. Update CHANGELOG.md and README status/examples.
  3. Run python -m ruff check src tests and python -m pytest tests -q.
  4. Build distributions: python -m build.
  5. Upload to TestPyPI first, verify install, then publish to PyPI.

License

Apache-2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

riff_kg_kit-0.7.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

riff_kg_kit-0.7.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file riff_kg_kit-0.7.0.tar.gz.

File metadata

  • Download URL: riff_kg_kit-0.7.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for riff_kg_kit-0.7.0.tar.gz
Algorithm Hash digest
SHA256 02675a48efa880623ce556a6961c8da5dbb18ece75bd87e0c3117f1924a06f11
MD5 f2c041c8019ba7583d850b3a1fba10b7
BLAKE2b-256 887e19a42fe05850488b0894386c5d2a4a03aaadab8380c618acef11df71d5a1

See more details on using hashes here.

File details

Details for the file riff_kg_kit-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: riff_kg_kit-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for riff_kg_kit-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c5f7cf3a83545382a83ae6fd6f7fc95477adeb865dfea84a32e565bf551709a
MD5 82fbaa64510d123db1fe43714d1fe53e
BLAKE2b-256 f95a1414ea4306cb5e12008ff5452531c66d14cc95baa39a46a4de11a36c472d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page