Improve KG chunk selection documentation and configuration clarity
This commit is contained in:
parent
3acb32f547
commit
6cab68bb47
2 changed files with 18 additions and 6 deletions
16
env.example
16
env.example
|
|
@ -71,12 +71,20 @@ ENABLE_LLM_CACHE=true
|
||||||
# MAX_RELATION_TOKENS=10000
|
# MAX_RELATION_TOKENS=10000
|
||||||
### control the maximum tokens send to LLM (include entities, raltions and chunks)
|
### control the maximum tokens send to LLM (include entities, raltions and chunks)
|
||||||
# MAX_TOTAL_TOKENS=30000
|
# MAX_TOTAL_TOKENS=30000
|
||||||
### chunk selection strategies for KG: WEIGHT or VECTOR
|
|
||||||
KG_CHUNK_PICK_METHOD=VECTOR
|
### maximum number of related chunks per source entity or relation
|
||||||
### maximum number of related chunks per source entity or relation (higher values increase re-ranking time)
|
### The chunk picker uses this value to determine the total number of chunks selected from KG(knowledge graph)
|
||||||
|
### Higher values increase re-ranking time
|
||||||
# RELATED_CHUNK_NUMBER=5
|
# RELATED_CHUNK_NUMBER=5
|
||||||
|
|
||||||
### Reranker configuration (Set ENABLE_RERANK to true in reranking model is configed)
|
### chunk selection strategies
|
||||||
|
### VECTOR: Pick KG chunks by vector similarity, delivered chunks to the LLM aligning more closely with naive retrieval
|
||||||
|
### WEIGHT: Pick KG chunks by entity and chunk weight, delivered more solely KG related chunks to the LLM
|
||||||
|
### If reranking is enabled, the impact of chunk selection strategies will be diminished.
|
||||||
|
# KG_CHUNK_PICK_METHOD=VECTOR
|
||||||
|
|
||||||
|
### Reranking configuration
|
||||||
|
### Reranker Set ENABLE_RERANK to true in reranking model is configed
|
||||||
# ENABLE_RERANK=True
|
# ENABLE_RERANK=True
|
||||||
### Minimum rerank score for document chunk exclusion (set to 0.0 to keep all chunks, 0.6 or above if LLM is not strong enought)
|
### Minimum rerank score for document chunk exclusion (set to 0.0 to keep all chunks, 0.6 or above if LLM is not strong enought)
|
||||||
# MIN_RERANK_SCORE=0.0
|
# MIN_RERANK_SCORE=0.0
|
||||||
|
|
|
||||||
|
|
@ -2779,9 +2779,12 @@ async def _find_related_text_unit_from_entities(
|
||||||
entity_info["sorted_chunks"] = sorted_chunks
|
entity_info["sorted_chunks"] = sorted_chunks
|
||||||
total_entity_chunks += len(sorted_chunks)
|
total_entity_chunks += len(sorted_chunks)
|
||||||
|
|
||||||
# Step 4: Apply the selected chunk selection algorithm
|
|
||||||
selected_chunk_ids = [] # Initialize to avoid UnboundLocalError
|
selected_chunk_ids = [] # Initialize to avoid UnboundLocalError
|
||||||
|
|
||||||
|
# Step 4: Apply the selected chunk selection algorithm
|
||||||
|
# Pick by vector similarity:
|
||||||
|
# The order of text chunks aligns with the naive retrieval's destination.
|
||||||
|
# When reranking is disabled, the text chunks delivered to the LLM tend to favor naive retrieval.
|
||||||
if kg_chunk_pick_method == "VECTOR" and query and chunks_vdb:
|
if kg_chunk_pick_method == "VECTOR" and query and chunks_vdb:
|
||||||
num_of_chunks = int(max_related_chunks * len(entities_with_chunks) / 2)
|
num_of_chunks = int(max_related_chunks * len(entities_with_chunks) / 2)
|
||||||
|
|
||||||
|
|
@ -2822,7 +2825,8 @@ async def _find_related_text_unit_from_entities(
|
||||||
kg_chunk_pick_method = "WEIGHT"
|
kg_chunk_pick_method = "WEIGHT"
|
||||||
|
|
||||||
if kg_chunk_pick_method == "WEIGHT":
|
if kg_chunk_pick_method == "WEIGHT":
|
||||||
# Apply linear gradient weighted polling algorithm
|
# Pick by entity and chunk weight:
|
||||||
|
# When reranking is disabled, delivered more solely KG related chunks to the LLM
|
||||||
selected_chunk_ids = pick_by_weighted_polling(
|
selected_chunk_ids = pick_by_weighted_polling(
|
||||||
entities_with_chunks, max_related_chunks, min_related_chunks=1
|
entities_with_chunks, max_related_chunks, min_related_chunks=1
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue