Simplify embedding func extraction
This commit is contained in:
parent
ac3b5605a1
commit
bac09118d5
1 changed files with 3 additions and 24 deletions
|
|
@ -2752,7 +2752,6 @@ async def _find_related_text_unit_from_entities(
|
||||||
selected_chunk_ids = [] # Initialize to avoid UnboundLocalError
|
selected_chunk_ids = [] # Initialize to avoid UnboundLocalError
|
||||||
|
|
||||||
if kg_chunk_pick_method == "VECTOR" and query and chunks_vdb:
|
if kg_chunk_pick_method == "VECTOR" and query and chunks_vdb:
|
||||||
# Calculate num_of_chunks = max_related_chunks * len(entity_info) / 2
|
|
||||||
num_of_chunks = int(max_related_chunks * len(entities_with_chunks) / 2)
|
num_of_chunks = int(max_related_chunks * len(entities_with_chunks) / 2)
|
||||||
|
|
||||||
# Get embedding function from global config
|
# Get embedding function from global config
|
||||||
|
|
@ -2762,15 +2761,7 @@ async def _find_related_text_unit_from_entities(
|
||||||
kg_chunk_pick_method = "WEIGHT"
|
kg_chunk_pick_method = "WEIGHT"
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
# Extract the actual callable function from EmbeddingFunc
|
actual_embedding_func = embedding_func_config.func
|
||||||
if hasattr(embedding_func_config, "func"):
|
|
||||||
actual_embedding_func = embedding_func_config.func
|
|
||||||
else:
|
|
||||||
logger.warning(
|
|
||||||
"Invalid embedding function format, falling back to WEIGHT method"
|
|
||||||
)
|
|
||||||
kg_chunk_pick_method = "WEIGHT"
|
|
||||||
actual_embedding_func = None
|
|
||||||
|
|
||||||
selected_chunk_ids = None
|
selected_chunk_ids = None
|
||||||
if actual_embedding_func:
|
if actual_embedding_func:
|
||||||
|
|
@ -3037,17 +3028,13 @@ async def _find_related_text_unit_from_relations(
|
||||||
total_relation_chunks += len(sorted_chunks)
|
total_relation_chunks += len(sorted_chunks)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Find {total_relation_chunks} additional relations-related chunks ({len(removed_entity_chunk_ids)} duplicated chunks removed)"
|
f"Find {total_relation_chunks} additional chunks in {len(relations_with_chunks)} relations ({len(removed_entity_chunk_ids)} duplicated chunks removed)"
|
||||||
)
|
|
||||||
logger.debug(
|
|
||||||
f"Only {len(relations_with_chunks)} out of {len(edge_datas)} relations have additional chunks after chunk deduplication"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Step 4: Apply the selected chunk selection algorithm
|
# Step 4: Apply the selected chunk selection algorithm
|
||||||
selected_chunk_ids = [] # Initialize to avoid UnboundLocalError
|
selected_chunk_ids = [] # Initialize to avoid UnboundLocalError
|
||||||
|
|
||||||
if kg_chunk_pick_method == "VECTOR" and query and chunks_vdb:
|
if kg_chunk_pick_method == "VECTOR" and query and chunks_vdb:
|
||||||
# Calculate num_of_chunks = max_related_chunks * len(entity_info) / 2
|
|
||||||
num_of_chunks = int(max_related_chunks * len(relations_with_chunks) / 2)
|
num_of_chunks = int(max_related_chunks * len(relations_with_chunks) / 2)
|
||||||
|
|
||||||
# Get embedding function from global config
|
# Get embedding function from global config
|
||||||
|
|
@ -3057,15 +3044,7 @@ async def _find_related_text_unit_from_relations(
|
||||||
kg_chunk_pick_method = "WEIGHT"
|
kg_chunk_pick_method = "WEIGHT"
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
# Extract the actual callable function from EmbeddingFunc
|
actual_embedding_func = embedding_func_config.func
|
||||||
if hasattr(embedding_func_config, "func"):
|
|
||||||
actual_embedding_func = embedding_func_config.func
|
|
||||||
else:
|
|
||||||
logger.warning(
|
|
||||||
"Invalid embedding function format, falling back to WEIGHT method"
|
|
||||||
)
|
|
||||||
kg_chunk_pick_method = "WEIGHT"
|
|
||||||
actual_embedding_func = None
|
|
||||||
|
|
||||||
if actual_embedding_func:
|
if actual_embedding_func:
|
||||||
selected_chunk_ids = await vector_similarity_sorting(
|
selected_chunk_ids = await vector_similarity_sorting(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue