neo4j-document-import-skill

Ingests unstructured and semi-structured documents into Neo4j as a knowledge graph. Use when chunking PDFs, HTML, plain text, or Markdown; extracting entities and relationships from text with an LLM (SimpleKGPipeline, neo4j-graphrag); loading JSON via apoc.load.json; building Document→Chunk→Entity g

By neo4j-contrib · 632 installs

npx skills add neo4j-contrib/neo4j-skills --skill neo4j-document-import-skill

Source repository · Upstream listing

Neo4j Document Import Skill When to Use Ingesting PDFs, HTML, plain text, Markdown into Neo4j as a knowledge graph Chunking documents and storing :Chunk nodes with embeddings Extracting entities and relationships from text with an LLM Using SimpleKGPipeline (neo4j graphrag) programmatically Using Neo4j LLM Graph Builder (no code web UI) Loading semi structured JSON via apoc.load.json Connecting LangChain or LlamaIndex document loaders to Neo4j When NOT to Use Structured CSV / relational data → neo4j import skill GraphRAG retrieval after ingestion → neo4j graphrag skill Vector index creation → neo4j vector search skill Cypher query writing → neo4j cypher skill Approach Decision Table Situation Approach No code; drag and drop UX wanted LLM Graph Builder web UI Programmatic pipeline; PDFs/text SimpleKGPipeline (neo4j graphrag) JSON / REST API responses apoc.load.json or Python + UNWIND LangChain already in stack Neo4jGraph + document loader LlamaIndex already in stack Neo4jQueryEngine / Neo4jVectorStore Chunk only (no entity extraction) Manual chunking + MERGE pattern Install Requires: neo4j =5.17.0 (driver 6.x supported), Python =3.10, Neo4j =5.18.1 (Aura =5.18.0). Step 1 — Define Graph Schema Schema controls what the LLM extracts. Define before pipeline construction. Use Option B for production; Option A for prototyping; "EXTRACTED" only for exploration. Step 2 — SimpleKGPipeline Setup LLM alternatives (same interface): AnthropicLLM(model name="claude 3 5 sonnet 20241022") VertexAILLM(model name="gemini 2.0 flash") OllamaLLM(model name="llama3") — local; no API key needed BedrockLLM(model id="anthropic.claude 3 5 sonnet 20241022 v2:0") — Amazon Bedrock (v1.15.0+) Step 3 — Run the Pipeline document metadata dict is stored as properties on the :Document node. Step 4 — Chunking Configuration Default splitter: FixedSizeSplitter(chunk size=300, chunk overlap=50) . Chunking guidance: Document type chunk size chunk overlap Dense technical text 256–512 50–80 Narrative / news articles 512–1024 80–128 Legal / financial docs 256–384 40–64 Rule: chunk must fit within LLM context for extraction + within embedding model limits. GPT 4o: 128k context; text embedding 3 small : 8191 tokens. Never set chunk size 2048. Step 5 — Entity Resolution Merge duplicate extracted entities after pipeline run. Run resolvers after ingestion, not inline — bulk merges are faster. Resulting Graph Structure Pipeline always produces this lexical graph layer: Entity extraction adds: Verify after ingestion: LLM Graph Builder (No Code UI) Use when: non developers need to ingest docs; rapid prototyping; no Python environment. Hosted : https://llm graph builder.neo4jlabs.com/ Local (Docker): Supported sources: PDF, plain text, Markdown, images, web pages, YouTube transcripts, S3/GCS bucket uploads. LLM providers: OpenAI, Gemini, Claude, Llama3, Diffbot, Qwen. Limitations: best with long form English text; poor on tabular data (use neo4j import skill for CSV/Excel); visual diagrams not extracted. APOC JSON Ingestion (Semi Structured) Use when source is JSON from REST APIs, S3, or file exports. Local file: apoc.load.json("file:///import/data.json") . File must be in $NEO4J HOME/import/ or APOC allowlist configured. Check APOC available: RETURN apoc.version() . APOC is included on all Aura tiers. LangChain Integration Pattern For entity extraction with LangChain: use LLMGraphTransformer (from langchain experimental.graph transformers ). Produces same :Document / :Chunk /entity pattern. Constraints and Indexes (Run Before Ingestion) Do not start ingestion until all indexes are ONLINE: If rows returned: wait, then re run. ONLINE = safe to ingest. Common Errors Error Cause Fix LLM extracts node types not in schema Schema too loose or "EXTRACTED" mode Define explicit entities + patterns ; use Option B schema MissingEmbedderError embedder= omitted Always pass embedder= even if not doing vector search — pipeline stores embeddings on Chunk nodes Zero entities extracted LLM context overflow Reduce chunk size ; switch to model with larger context Duplicate entity nodes after ingestion Entity resolution not run Run SinglePropertyExactMatchResolver after bulk ingest apoc.load.json permission denied APOC allowlist not configured Add URL to apoc.import.file.enabled=true and dbms.security.allow csv import from file urls=true Chunking loses sentence mid way approximate=False (default) cuts at exact token count Set approximate=True in FixedSizeSplitter chunk size too large → LLM timeouts Extraction prompt + chunk exceeds context Keep chunk size ≤ 512 for GPT 4o extraction; ≤ 2048 absolute max SpaCySemanticMatchResolver fails on Python 3.14 spaCy not supported on 3.14+ Use FuzzyMatchResolver or downgrade to Python 3.13 neo4j driver package not found Deprecated package name since 6.0 Use neo4j package: pip install neo4j =5.17.0 ValidationError on NodeType with no properties NodeType requires ≥1 property since v1.13.0 Add at least PropertyType(name="name", type="STRING") ; string list labels get it automatically from pdf deprecation warning from pdf=True removed in v1.15.0 Use from file=True instead response format in model params ignored SimpleKGPipeline auto enables structured output for OpenAI/VertexAI (v1.14.0+) Remove response format from model params ; the pipeline manages it Verification Checklist [ ] Constraints created and ONLINE before ingestion starts [ ] Vector index created before storing embeddings [ ] chunk size within embedding model limit (≤2048; ≤512 for extraction) [ ] chunk overlap set to 10–15% of chunk size [ ] Document → HAS CHUNK → Chunk pattern used (enables graph traversal in retrieval) [ ] document metadata populated with source identifier [ ] Entity resolver run after bulk ingestion [ ] apoc.version() confirmed if using apoc.load.json [ ] .env has API keys; .env in .gitignore [ ] Verify structure: MATCH (d:Document) [:HAS CHUNK] (c:Chunk) RETURN count(c) [ ] Verify entities: MATCH (c:Chunk) [:MENTIONS] (e) RETURN labels(e)[0], count( ) GraphSchema — Current API (≥1.8.0) entities / relations / potential schema are deprecated. Use schema=GraphSchema(...) . schema="FREE" (no guidance) or schema="EXTRACTED" (LLM infers types) — exploration only, noisier output. Auto Extract Schema from Text (v1.15.0+) When no schema is passed to SimpleKGPipeline , SchemaFromTextExtractor runs automatically. To run it explicitly: Parquet Export (experimental, v1.14.0+) LexicalGraphConfig — Customize Labels Override default lexical layer labels (keep defaults unless integrating with existing graph): Custom Document Loaders Default file loader auto dispatches by extension ( .pdf → PdfLoader , .md → MarkdownLoader ). Supports fsspec URIs ( s3:// , gcs:// ). Subclass DataLoader for HTML/web/custom formats: Chunking strategy by use case and full resolver config: [references/kg construction.md](references/kg construction.md). References Load on demand: [neo4j graphrag KG Builder guide](https://neo4j.com/docs/neo4j graphrag python/current/user guide kg builder.html) [neo4j graphrag library overview](https://neo4j.com/docs/neo4j graphrag python/current/) [LLM Graph Builder (hosted)](https://llm graph builder.neo4jlabs.com/) [LLM Graph Builder GitHub](https://github.com/neo4j labs/llm graph builder) [APOC load procedures](https://neo4j.com/docs/apoc/current/import/) [GraphAcademy: Building Knowledge Graphs with LLMs](https://graphacademy.neo4j.com/courses/llm knowledge graph construction/) [LangChain Neo4j Integration](https://python.langchain.com/docs/integrations/graphs/neo4j cypher/) [LlamaIndex Neo4jQueryEngine](https://docs.llamaindex.ai/en/stable/examples/index structs/knowledge graph/Neo4jKGIndexDemo/) [Extended KG Construction Reference](references/kg construction.md)