How to Build a Research Knowledge Graph Agent for Complex Queries

For Data scientists working with research corpora · Based on Cole Medin RAG 2.0 Agentic Knowledge System

// TL;DR

Data scientists working with research corpora use Cole Medin's RAG 2.0 to answer both factual questions ('What are the side effects of Drug A?') and relational ones ('Which institutions collaborated on Drug A and Drug B trials?') over the same document set. By ingesting papers into both pgvector and a Neo4j knowledge graph — where drugs, institutions, and trials become nodes with typed relationships — an agent routes each query to the right store. Use it when your analysis depends on traversing connections between entities that vector similarity can't surface.

Why do research corpora demand more than vector search?

Research data is dense with entities and relationships: papers cite papers, institutions collaborate, drugs are studied in trials, authors co-publish. A vector-only RAG system handles 'What are the reported side effects of Drug A?' by retrieving similar chunks — but it cannot answer 'Which institutions co-authored studies on both Drug A and Drug B?' because that requires traversing relationships, not matching semantic similarity.

RAG 2.0 addresses this with Dual Representation. You chunk and embed papers into a vector database for factual lookups, and simultaneously extract entities (drugs, institutions, trials, authors) and relationships (conducted_by, studied_in, cites) into a Neo4j knowledge graph. An agent then reasons about which representation answers each query — mirroring how a researcher decides between skimming a paper and mapping a citation network.

How does automated entity extraction work for papers?

During ingestion, the system uses Graffiti — a Python knowledge graph library — with a lightweight ingestion LLM to read each document and extract entities and relationships, writing them as 'episodes' into Neo4j. This is why graph ingestion takes minutes per document while vector ingestion takes seconds: the LLM must parse and structure the relational content of every paper.

Use a cheap model like GPT-4.1 Nano for extraction across a large corpus — reserving your capable main LLM for the agent's reasoning. Monitor Graffiti episodes in the Neo4j dashboard as they populate, and never interrupt ingestion, since a partial graph produces incomplete relational answers. Run on a fresh project with --clean; never on data you can't afford to lose.

How do you encode research-specific routing logic?

The agent's system prompt in prompts.py must describe your specific entity and relationship types. For a clinical corpus, tell the agent to use the knowledge graph for questions about collaborations, co-occurrence across trials, or how drugs and institutions connect, and to use vector search for descriptive factual questions about a single drug, method, or finding. For multi-hop analytical questions spanning both breadth and relationships, instruct it to use both tools.

Be explicit — a generic prompt yields inconsistent routing. Since LLMs are non-deterministic, validate on answer quality across repeated runs using the CLI, which surfaces the agent's tool selection. If relational queries keep hitting vector search, refine the prompt rules; the infrastructure is not the problem.

What analytical workflows does this unlock?

Once built, you can ask questions that combine literature retrieval with network reasoning: identify which research groups bridge two subfields, trace how a finding propagates across cited works, or compare treatment approaches across institutions. The knowledge graph makes relationship-driven hypotheses queryable in natural language, while the vector store keeps granular factual detail one hop away.

Because querying is fast at runtime regardless of ingestion cost, you can iterate on analytical questions interactively — treating the agent as a research assistant that knows both the contents and the connective structure of your corpus.

Next step: Take twenty papers from your corpus, define your key entity and relationship types, ingest them into the dual-store system, and test one factual and one collaboration-network query through the CLI to confirm the agent routes each correctly.

// FREQUENTLY ASKED QUESTIONS

How accurately does the ingestion LLM extract research entities?

Extraction quality depends on the ingestion LLM and how clearly your documents express entities and relationships. A lightweight model like GPT-4.1 Nano handles well-structured research text adequately, but for nuanced scientific relationships you may validate a sample of extracted episodes in the Neo4j dashboard. If extraction misses key relationships, consider a slightly stronger ingestion model — balancing accuracy against per-document cost across a large corpus.

Can I query the knowledge graph directly with Cypher for analysis?

Yes — since the graph lives in Neo4j, you can run Cypher queries directly against it for network analysis outside the agent, in addition to natural-language queries through the agent. This dual access lets you use the agent for exploratory questions and Cypher for precise, reproducible analytical queries over the same entity and relationship structure.

How do I handle a corpus too large to ingest at once?

Batch ingestion in chunks and run it off-hours, since graph extraction is minutes per document. Avoid --clean after the first run so you don't wipe prior work — ingest incrementally instead. Keep the ingestion LLM lightweight to control cost at scale, and monitor Graffiti episodes to confirm each batch completes fully before starting the next.