Back to Showcases
EnterpriseAdvanced

Knowledge Base with LLM-Extracted Graph

Typed entities and edges extracted from your documents, with provenance

Vector SearchLLM Extraction (BYOK)Typed Entities and EdgesHybrid Query
Per-Edge
Edge Provenance
Before Spend
Cost Preview
Verify / Reject
Curation
All
Tests Passed

The Scenario

Documents are chunked, embedded, and stored. You point the collection at any OpenAI-compatible model with your own key, preview the cost, then run extraction: the model proposes typed entities and edges, each with provenance back to the source document and chunk. You verify, reject, or re-extract. At query time, a hybrid query seeds by similarity and traverses the extracted typed edges to surface connected knowledge. The graph earns its place on structure-heavy, multi-hop questions where the typed connections matter; it is not positioned as a universal lift over plain vector search.

Key Results

  • Typed entities and edges extracted by an LLM, each with full provenance
  • Cost preview before any tokens are spent; verify / reject / re-extract loop
  • Hybrid query connects related knowledge through extracted typed edges
  • Best fit on structure-heavy, multi-hop questions, not as a universal lift
Per-Edge
Edge Provenance
Before Spend
Cost Preview
Verify / Reject
Curation
All
Tests Passed

The Code

Everything above, in a few lines of Python.

python
# Extraction is opt-in, bring your own key. Preview cost before spending.
client.extraction.set_llm_config("knowledge_base",
    base_url="https://openrouter.ai/api/v1",
    api_key="sk-or-...", model_name="openai/gpt-4o-mini",
    temperature=0.0, max_tokens=2048)

estimate = client.extraction.cost_preview("knowledge_base", chunks)
result = client.extraction.start_extraction("knowledge_base", chunks)

# Query: seed by similarity, traverse the extracted typed edges, rank.
answer = (
    client.graph.query("knowledge_base")
    .vector_similar(question_embedding, k=20)
    .traverse("MENTIONS", direction="outgoing")
    .vector_rank(question_embedding, k=10)
    .return_nodes()
)

Try it yourself

Clone the repo, spin up SwarnDB, and run this showcase in minutes.

View on GitHub