refactor: extract file path length limit to shared constant

• Add DEFAULT_MAX_FILE_PATH_LENGTH constant
• Replace hardcoded 4090 in Milvus impl
This commit is contained in:
yangdx 2025-07-26 10:45:03 +08:00
parent 8e7014d366
commit c8c3545454
3 changed files with 11 additions and 3 deletions

View File

@ -26,6 +26,9 @@ DEFAULT_RELATED_CHUNK_NUMBER = 5
# Separator for graph fields
GRAPH_FIELD_SEP = "<SEP>"
# File path configuration for vector and graph database
DEFAULT_MAX_FILE_PATH_LENGTH = 4090
# Logging configuration defaults
DEFAULT_LOG_MAX_BYTES = 10485760 # Default 10MB
DEFAULT_LOG_BACKUP_COUNT = 5 # Default 5 backups

View File

@ -5,6 +5,7 @@ from dataclasses import dataclass
import numpy as np
from lightrag.utils import logger, compute_mdhash_id
from ..base import BaseVectorStorage
from ..constants import DEFAULT_MAX_FILE_PATH_LENGTH
import pipmaster as pm
if not pm.is_installed("pymilvus"):
@ -47,7 +48,7 @@ class MilvusVectorDBStorage(BaseVectorStorage):
FieldSchema(
name="file_path",
dtype=DataType.VARCHAR,
max_length=4090,
max_length=DEFAULT_MAX_FILE_PATH_LENGTH,
nullable=True,
),
]
@ -64,7 +65,7 @@ class MilvusVectorDBStorage(BaseVectorStorage):
FieldSchema(
name="file_path",
dtype=DataType.VARCHAR,
max_length=4090,
max_length=DEFAULT_MAX_FILE_PATH_LENGTH,
nullable=True,
),
]

View File

@ -43,6 +43,7 @@ from .constants import (
DEFAULT_MAX_RELATION_TOKENS,
DEFAULT_MAX_TOTAL_TOKENS,
DEFAULT_RELATED_CHUNK_NUMBER,
DEFAULT_MAX_FILE_PATH_LENGTH,
)
from .kg.shared_storage import get_storage_keyed_lock
import time
@ -3154,7 +3155,10 @@ def build_file_path(already_file_paths, data_list, target):
file_paths_set.add(cur_file_path)
# check the length
if len(file_paths) + len(GRAPH_FIELD_SEP + cur_file_path) < 4090:
if (
len(file_paths) + len(GRAPH_FIELD_SEP + cur_file_path)
< DEFAULT_MAX_FILE_PATH_LENGTH
):
# append
file_paths += (
GRAPH_FIELD_SEP + cur_file_path if file_paths else cur_file_path