Skip to content

Conversation

@NeelM0906
Copy link

@NeelM0906 NeelM0906 commented Oct 8, 2025

Added three new REST API endpoints for direct knowledge graph manipulation:

  • POST /graph/entity/create: Create new entities in the knowledge graph
  • POST /graph/relation/create: Create relationships between entities
  • POST /graph/entities/merge: Merge duplicate/misspelled entities while preserving relationships

The merge endpoint is particularly useful for consolidating entities discovered after document processing, fixing spelling errors, and cleaning up the knowledge graph. All relationships from source entities are transferred to the target entity, with intelligent handling of duplicate relationships.

Updated API documentation in lightrag/api/README.md with usage examples for all three endpoints.

Added three new REST API endpoints for direct knowledge graph manipulation, enabling users to create entities, create relationships, and merge duplicate
or misspelled entities while preserving their relationships.

Related Issues

Addresses the need for manual knowledge graph cleanup and entity consolidation after document processing, particularly for fixing misspelled entity
names and merging duplicate entities.

Changes Made

  • Added POST /graph/entity/create endpoint to create new entities in the knowledge graph
  • Added POST /graph/relation/create endpoint to create relationships between existing entities
  • Added POST /graph/entities/merge endpoint to consolidate duplicate/misspelled entities while preserving all relationships
  • Created Pydantic request models: EntityCreateRequest, RelationCreateRequest, and EntityMergeRequest
  • Updated lightrag/api/routers/graph_routes.py with endpoint implementations
  • Updated lightrag/api/README.md with comprehensive documentation and usage examples for all three endpoints

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (if necessary)
  • Unit tests added (if applicable)

Additional Notes

The merge endpoint leverages the existing amerge_entities functionality in the LightRAG core library, which intelligently handles relationship transfer,
duplicate relationship merging, and vector embedding updates. This feature is particularly valuable for post-processing knowledge graphs where entity
name variations or spelling errors create fragmented graph structures.

Added three new REST API endpoints for direct knowledge graph manipulation:

- POST /graph/entity/create: Create new entities in the knowledge graph
- POST /graph/relation/create: Create relationships between entities
- POST /graph/entities/merge: Merge duplicate/misspelled entities while preserving relationships

The merge endpoint is particularly useful for consolidating entities discovered after document processing, fixing spelling errors, and cleaning up the knowledge graph. All relationships from source entities are transferred to the target entity, with intelligent handling of duplicate relationships.

Updated API documentation in lightrag/api/README.md with usage examples for all three endpoints.
@danielaskdd
Copy link
Collaborator

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

  - Changed create_entity to use rag.acreate_entity() instead of direct graph manipulation
  - Changed create_relation to use rag.acreate_relation() instead of direct graph manipulation
  - This ensures vector embeddings are created and entities/relations are searchable
  - Adds proper concurrency locks and metadata population
@danielaskdd
Copy link
Collaborator

@codex review again

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

@NeelM0906
Copy link
Author

If all good, please merge.

@danielaskdd danielaskdd merged commit 85d1a56 into HKUDS:main Oct 10, 2025
1 check passed
@danielaskdd
Copy link
Collaborator

Thanks for sharing.

@NeelM0906
Copy link
Author

Thanks for the review and merge. I look forward to continue contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants