Commit f53ede487f5b50726a34bd5e12fe25e2a6b7ebec
1 parent
74330086
deepwalk refactor for memsave and perfermance optimize
Showing
1 changed file
with
8 additions
and
3 deletions
Show diff stats
offline_tasks/scripts/load_index_to_redis.py
| @@ -42,11 +42,16 @@ def load_index_file(file_path, redis_client, key_prefix, expire_seconds=None): | @@ -42,11 +42,16 @@ def load_index_file(file_path, redis_client, key_prefix, expire_seconds=None): | ||
| 42 | continue | 42 | continue |
| 43 | 43 | ||
| 44 | parts = line.split('\t') | 44 | parts = line.split('\t') |
| 45 | - if len(parts) != 2: | ||
| 46 | - logger.warning(f"Invalid line format: {line}") | 45 | + if len(parts) < 2: |
| 46 | + logger.warning(f"Invalid line format (expected at least 2 fields): {line}") | ||
| 47 | continue | 47 | continue |
| 48 | 48 | ||
| 49 | - key_suffix, value = parts | 49 | + # 支持2字段和3字段格式 |
| 50 | + # 格式1 (2字段): item_id \t similar_items | ||
| 51 | + # 格式2 (3字段): item_id \t item_name \t similar_items (推荐格式) | ||
| 52 | + # 取第一个字段作为key,最后一个字段作为value | ||
| 53 | + key_suffix = parts[0] | ||
| 54 | + value = parts[-1] | ||
| 50 | redis_key = f"{key_prefix}:{key_suffix}" | 55 | redis_key = f"{key_prefix}:{key_suffix}" |
| 51 | 56 | ||
| 52 | # 存储到Redis | 57 | # 存储到Redis |