Update README.md
Browse files
README.md
CHANGED
@@ -441,11 +441,15 @@ if __name__ == "__main__":
|
|
441 |
- [Direct OpenAI Example](examples/lightrag_llamaindex_direct_demo.py)
|
442 |
- [LiteLLM Proxy Example](examples/lightrag_llamaindex_litellm_demo.py)
|
443 |
|
|
|
|
|
444 |
### Conversation History Support
|
445 |
|
446 |
|
447 |
LightRAG now supports multi-turn dialogue through the conversation history feature. Here's how to use it:
|
448 |
|
|
|
|
|
449 |
```python
|
450 |
# Create conversation history
|
451 |
conversation_history = [
|
@@ -506,6 +510,8 @@ response_custom = rag.query(
|
|
506 |
print(response_custom)
|
507 |
```
|
508 |
|
|
|
|
|
509 |
### Separate Keyword Extraction
|
510 |
|
511 |
We've introduced a new function `query_with_separate_keyword_extraction` to enhance the keyword extraction capabilities. This function separates the keyword extraction process from the user's prompt, focusing solely on the query to improve the relevance of extracted keywords.
|
@@ -519,7 +525,8 @@ The function operates by dividing the input into two parts:
|
|
519 |
|
520 |
It then performs keyword extraction exclusively on the `user query`. This separation ensures that the extraction process is focused and relevant, unaffected by any additional language in the `prompt`. It also allows the `prompt` to serve purely for response formatting, maintaining the intent and clarity of the user's original question.
|
521 |
|
522 |
-
|
|
|
523 |
|
524 |
This `example` shows how to tailor the function for educational content, focusing on detailed explanations for older students.
|
525 |
|
@@ -531,67 +538,6 @@ rag.query_with_separate_keyword_extraction(
|
|
531 |
)
|
532 |
```
|
533 |
|
534 |
-
### Insert Custom KG
|
535 |
-
|
536 |
-
```python
|
537 |
-
custom_kg = {
|
538 |
-
"chunks": [
|
539 |
-
{
|
540 |
-
"content": "Alice and Bob are collaborating on quantum computing research.",
|
541 |
-
"source_id": "doc-1"
|
542 |
-
}
|
543 |
-
],
|
544 |
-
"entities": [
|
545 |
-
{
|
546 |
-
"entity_name": "Alice",
|
547 |
-
"entity_type": "person",
|
548 |
-
"description": "Alice is a researcher specializing in quantum physics.",
|
549 |
-
"source_id": "doc-1"
|
550 |
-
},
|
551 |
-
{
|
552 |
-
"entity_name": "Bob",
|
553 |
-
"entity_type": "person",
|
554 |
-
"description": "Bob is a mathematician.",
|
555 |
-
"source_id": "doc-1"
|
556 |
-
},
|
557 |
-
{
|
558 |
-
"entity_name": "Quantum Computing",
|
559 |
-
"entity_type": "technology",
|
560 |
-
"description": "Quantum computing utilizes quantum mechanical phenomena for computation.",
|
561 |
-
"source_id": "doc-1"
|
562 |
-
}
|
563 |
-
],
|
564 |
-
"relationships": [
|
565 |
-
{
|
566 |
-
"src_id": "Alice",
|
567 |
-
"tgt_id": "Bob",
|
568 |
-
"description": "Alice and Bob are research partners.",
|
569 |
-
"keywords": "collaboration research",
|
570 |
-
"weight": 1.0,
|
571 |
-
"source_id": "doc-1"
|
572 |
-
},
|
573 |
-
{
|
574 |
-
"src_id": "Alice",
|
575 |
-
"tgt_id": "Quantum Computing",
|
576 |
-
"description": "Alice conducts research on quantum computing.",
|
577 |
-
"keywords": "research expertise",
|
578 |
-
"weight": 1.0,
|
579 |
-
"source_id": "doc-1"
|
580 |
-
},
|
581 |
-
{
|
582 |
-
"src_id": "Bob",
|
583 |
-
"tgt_id": "Quantum Computing",
|
584 |
-
"description": "Bob researches quantum computing.",
|
585 |
-
"keywords": "research application",
|
586 |
-
"weight": 1.0,
|
587 |
-
"source_id": "doc-1"
|
588 |
-
}
|
589 |
-
]
|
590 |
-
}
|
591 |
-
|
592 |
-
rag.insert_custom_kg(custom_kg)
|
593 |
-
```
|
594 |
-
|
595 |
</details>
|
596 |
|
597 |
## Insert
|
@@ -683,6 +629,70 @@ rag.insert(text_content.decode('utf-8'))
|
|
683 |
|
684 |
</details>
|
685 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
686 |
<details>
|
687 |
<summary><b>Citation Functionality</b></summary>
|
688 |
|
@@ -842,7 +852,8 @@ rag.delete_by_doc_id("doc_id")
|
|
842 |
|
843 |
LightRAG now supports comprehensive knowledge graph management capabilities, allowing you to create, edit, and delete entities and relationships within your knowledge graph.
|
844 |
|
845 |
-
|
|
|
846 |
|
847 |
```python
|
848 |
# Create new entity
|
@@ -865,7 +876,10 @@ relation = rag.create_relation("Google", "Gmail", {
|
|
865 |
})
|
866 |
```
|
867 |
|
868 |
-
|
|
|
|
|
|
|
869 |
|
870 |
```python
|
871 |
# Edit an existing entity
|
@@ -902,6 +916,8 @@ All operations are available in both synchronous and asynchronous versions. The
|
|
902 |
|
903 |
These operations maintain data consistency across both the graph database and vector database components, ensuring your knowledge graph remains coherent.
|
904 |
|
|
|
|
|
905 |
## Data Export Functions
|
906 |
|
907 |
### Overview
|
@@ -910,7 +926,8 @@ LightRAG allows you to export your knowledge graph data in various formats for a
|
|
910 |
|
911 |
### Export Functions
|
912 |
|
913 |
-
|
|
|
914 |
|
915 |
```python
|
916 |
# Basic CSV export (default format)
|
@@ -920,7 +937,10 @@ rag.export_data("knowledge_graph.csv")
|
|
920 |
rag.export_data("output.xlsx", file_format="excel")
|
921 |
```
|
922 |
|
923 |
-
|
|
|
|
|
|
|
924 |
|
925 |
```python
|
926 |
#Export data in CSV format
|
@@ -935,13 +955,18 @@ rag.export_data("graph_data.md", file_format="md")
|
|
935 |
# Export data in Text
|
936 |
rag.export_data("graph_data.txt", file_format="txt")
|
937 |
```
|
938 |
-
|
|
|
|
|
|
|
939 |
|
940 |
Include vector embeddings in the export (optional):
|
941 |
|
942 |
```python
|
943 |
rag.export_data("complete_data.csv", include_vector_data=True)
|
944 |
```
|
|
|
|
|
945 |
### Data Included in Export
|
946 |
|
947 |
All exports include:
|
|
|
441 |
- [Direct OpenAI Example](examples/lightrag_llamaindex_direct_demo.py)
|
442 |
- [LiteLLM Proxy Example](examples/lightrag_llamaindex_litellm_demo.py)
|
443 |
|
444 |
+
</details>
|
445 |
+
|
446 |
### Conversation History Support
|
447 |
|
448 |
|
449 |
LightRAG now supports multi-turn dialogue through the conversation history feature. Here's how to use it:
|
450 |
|
451 |
+
<details>
|
452 |
+
|
453 |
```python
|
454 |
# Create conversation history
|
455 |
conversation_history = [
|
|
|
510 |
print(response_custom)
|
511 |
```
|
512 |
|
513 |
+
</details>
|
514 |
+
|
515 |
### Separate Keyword Extraction
|
516 |
|
517 |
We've introduced a new function `query_with_separate_keyword_extraction` to enhance the keyword extraction capabilities. This function separates the keyword extraction process from the user's prompt, focusing solely on the query to improve the relevance of extracted keywords.
|
|
|
525 |
|
526 |
It then performs keyword extraction exclusively on the `user query`. This separation ensures that the extraction process is focused and relevant, unaffected by any additional language in the `prompt`. It also allows the `prompt` to serve purely for response formatting, maintaining the intent and clarity of the user's original question.
|
527 |
|
528 |
+
<details>
|
529 |
+
<summary> <b> Usage Example </b></summary>
|
530 |
|
531 |
This `example` shows how to tailor the function for educational content, focusing on detailed explanations for older students.
|
532 |
|
|
|
538 |
)
|
539 |
```
|
540 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
</details>
|
542 |
|
543 |
## Insert
|
|
|
629 |
|
630 |
</details>
|
631 |
|
632 |
+
<details>
|
633 |
+
<summary> <b> Insert Custom KG </b></summary>
|
634 |
+
|
635 |
+
```python
|
636 |
+
custom_kg = {
|
637 |
+
"chunks": [
|
638 |
+
{
|
639 |
+
"content": "Alice and Bob are collaborating on quantum computing research.",
|
640 |
+
"source_id": "doc-1"
|
641 |
+
}
|
642 |
+
],
|
643 |
+
"entities": [
|
644 |
+
{
|
645 |
+
"entity_name": "Alice",
|
646 |
+
"entity_type": "person",
|
647 |
+
"description": "Alice is a researcher specializing in quantum physics.",
|
648 |
+
"source_id": "doc-1"
|
649 |
+
},
|
650 |
+
{
|
651 |
+
"entity_name": "Bob",
|
652 |
+
"entity_type": "person",
|
653 |
+
"description": "Bob is a mathematician.",
|
654 |
+
"source_id": "doc-1"
|
655 |
+
},
|
656 |
+
{
|
657 |
+
"entity_name": "Quantum Computing",
|
658 |
+
"entity_type": "technology",
|
659 |
+
"description": "Quantum computing utilizes quantum mechanical phenomena for computation.",
|
660 |
+
"source_id": "doc-1"
|
661 |
+
}
|
662 |
+
],
|
663 |
+
"relationships": [
|
664 |
+
{
|
665 |
+
"src_id": "Alice",
|
666 |
+
"tgt_id": "Bob",
|
667 |
+
"description": "Alice and Bob are research partners.",
|
668 |
+
"keywords": "collaboration research",
|
669 |
+
"weight": 1.0,
|
670 |
+
"source_id": "doc-1"
|
671 |
+
},
|
672 |
+
{
|
673 |
+
"src_id": "Alice",
|
674 |
+
"tgt_id": "Quantum Computing",
|
675 |
+
"description": "Alice conducts research on quantum computing.",
|
676 |
+
"keywords": "research expertise",
|
677 |
+
"weight": 1.0,
|
678 |
+
"source_id": "doc-1"
|
679 |
+
},
|
680 |
+
{
|
681 |
+
"src_id": "Bob",
|
682 |
+
"tgt_id": "Quantum Computing",
|
683 |
+
"description": "Bob researches quantum computing.",
|
684 |
+
"keywords": "research application",
|
685 |
+
"weight": 1.0,
|
686 |
+
"source_id": "doc-1"
|
687 |
+
}
|
688 |
+
]
|
689 |
+
}
|
690 |
+
|
691 |
+
rag.insert_custom_kg(custom_kg)
|
692 |
+
```
|
693 |
+
|
694 |
+
</details>
|
695 |
+
|
696 |
<details>
|
697 |
<summary><b>Citation Functionality</b></summary>
|
698 |
|
|
|
852 |
|
853 |
LightRAG now supports comprehensive knowledge graph management capabilities, allowing you to create, edit, and delete entities and relationships within your knowledge graph.
|
854 |
|
855 |
+
<details>
|
856 |
+
<summary> <b> Create Entities and Relations </b></summary>
|
857 |
|
858 |
```python
|
859 |
# Create new entity
|
|
|
876 |
})
|
877 |
```
|
878 |
|
879 |
+
</details>
|
880 |
+
|
881 |
+
<details>
|
882 |
+
<summary> <b> Edit Entities and Relations </b></summary>
|
883 |
|
884 |
```python
|
885 |
# Edit an existing entity
|
|
|
916 |
|
917 |
These operations maintain data consistency across both the graph database and vector database components, ensuring your knowledge graph remains coherent.
|
918 |
|
919 |
+
</details>
|
920 |
+
|
921 |
## Data Export Functions
|
922 |
|
923 |
### Overview
|
|
|
926 |
|
927 |
### Export Functions
|
928 |
|
929 |
+
<details>
|
930 |
+
<summary> <b> Basic Usage </b></summary>
|
931 |
|
932 |
```python
|
933 |
# Basic CSV export (default format)
|
|
|
937 |
rag.export_data("output.xlsx", file_format="excel")
|
938 |
```
|
939 |
|
940 |
+
</details>
|
941 |
+
|
942 |
+
<details>
|
943 |
+
<summary> <b> Different File Formats supported </b></summary>
|
944 |
|
945 |
```python
|
946 |
#Export data in CSV format
|
|
|
955 |
# Export data in Text
|
956 |
rag.export_data("graph_data.txt", file_format="txt")
|
957 |
```
|
958 |
+
</details>
|
959 |
+
|
960 |
+
<details>
|
961 |
+
<summary> <b> Additional Options </b></summary>
|
962 |
|
963 |
Include vector embeddings in the export (optional):
|
964 |
|
965 |
```python
|
966 |
rag.export_data("complete_data.csv", include_vector_data=True)
|
967 |
```
|
968 |
+
</details>
|
969 |
+
|
970 |
### Data Included in Export
|
971 |
|
972 |
All exports include:
|