Turn a folder of academic PDFs into a knowledge graph you can actually talk to.
Chunk the papers, extract typed entities and relationships with an LLM, embed the chunks locally, store everything in Neo4j, then chat with an agent that has read-only tools over the graph.
| File | Work |
|---|---|
CoALA.pdf |
Sumers et al., A Cognitive Architecture for Language Agents (TMLR 02/2024) |
Simon_1970_...pdf |
Simon & Newell, Human Problem Solving: The State of the Theory in 1970 |
3640792.3675713.pdf |
Rege, Currano, Sirkin & Kim, Talking with your Car |
These PDFs are not redistributed — they are gitignored. Drop your own into
workshop-genai/data/.
pip install -r requirements.txt
pip install sentence-transformers pypdf python-dotenv
cp .env.example .env # then fill in your keyscd workshop-genai
python kg_builder.py --file CoALA.pdf # build the graph
python agent.py # chat with itagent.py runs a health check at startup, so there is no separate verify step.
| Key | Required | Notes |
|---|---|---|
NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD, NEO4J_DATABASE |
yes | Neo4j Aura or local |
GROQ_API_KEY |
yes (default) | free tier, generous |
MISTRAL_API_KEY |
only if LLM_PROVIDER=mistral |
free tier exhausts quickly |
Embeddings need no key at all. They run locally on
sentence-transformers/all-MiniLM-L6-v2 (384-d), so re-embedding is free and
never touches a rate limit.
Set LLM_PROVIDER in .env — one line, no code changes:
LLM_PROVIDER=groq # default, verified working
LLM_PROVIDER=mistral # free tier is easy to exhaust (429 code 1300)
LLM_PROVIDER=ollama # fully local; needs `ollama serve` + pip install ollamallm_config.py is the single place provider details live.
Ten node types, seven relationship types, seventeen allowed patterns — defined in
schema.py and drawn from what the papers actually discuss:
Agent · Architecture · Memory · Perception · Action
Vehicle · Concept · Theory · Method · Measurement
IMPLEMENTS · EXTENDS · PROVIDES · APPLIES_TO · MEASURES · CONTRADICTS · CITES
additional_* are all True on purpose. A too-strict schema silently drops
anything that does not fit the label list, which is how you end up with an
empty graph.
The Groq free tier is capped at 8000 tokens per minute on every usable chat
model — not requests. Read it live from x-ratelimit-limit-tokens.
Measured on real CoALA chunks: ~1500 prompt + ~400–1500 completion = ~1900–3500 tokens per chunk. Two consequences:
- Requests must be ~30 seconds apart.
LLM_MIN_INTERVALdefaults to30.0for Groq. An earlier value of2.0was derived from a requests/minute assumption and was ~15× too fast — that produced a wall of 429s. - Retry backoff must not use jitter. With
jitter=True,RetryRateLimitHandlerdraws a random wait, so retries fired after ~2 seconds while the server was asking for 21s, burning every attempt before the window could refill. It is nowjitter=False→ deterministic 30, 60, 120.
Also worth knowing: reasoning_tokens count against TPM. A reasoning model
can spend its whole output budget thinking and return nothing.
At 30s intervals, CoALA.pdf (31 chunks) takes ~16 minutes.
Both were found by running against the real API, not by tests:
-
Groq rejects the library's structured-output schema. Strict mode demands
additionalProperties: falseon every object;neo4j-graphrag'sNeo4jGraphdoes not set it onembedding_properties, so you get a hard400.ThrottledLLMtherefore reportssupports_structured_output = Falseand the extractor falls back to prompt-based JSON, which works everywhere. -
The stock prompt renders the schema as a Python dict repr. The model is handed a wall of single-quoted Python including internal flags:
al_relationship_types': True, 'additional_patterns': True}Same model, same text, measured directly:
Prompt Result stock ERExtractionTemplate{"nodes": [], "relationships": []}— 0 entitiesReadableSchemaTemplate13 nodes / 10 relationships ReadableSchemaTemplaterenders node types, relationship types and allowed directions as plain text.
All read-only:
| Tool | Purpose |
|---|---|
get-graph-schema |
node and relationship types |
query-graph |
Cypher, with a write-keyword guard |
describe-entity |
one entity and its neighbourhood |
search-documents |
vector search over chunks |
.env.example documents every key (copy to .env)
requirements.txt direct dependencies only
README.md
workshop-genai/
kg_builder.py PDF -> knowledge graph (single command)
agent.py interactive chat + startup health check
llm_config.py provider switch: groq | mistral | ollama
schema.py domain schema, index name, embedding dims
data/ your PDFs (gitignored) + screenshots

