Compare commits
4 Commits
df99e3ac76
...
29b4f43a27
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29b4f43a27 | ||
|
|
69dc20207d | ||
|
|
18979af604 | ||
|
|
74406f9be4 |
@@ -178,47 +178,23 @@ async def recommend(
|
||||
@router.get("/redis/user_pref")
|
||||
async def get_all_user_preferences():
|
||||
"""
|
||||
获取所有以 user_pref 为前缀的 Redis key 信息,按 account_id 分组
|
||||
获取所有以 user_pref 为前缀的 Redis key 信息
|
||||
"""
|
||||
try:
|
||||
from app.service.utils.redis_utils import Redis
|
||||
from app.service.recommendation_system.config import REDIS_KEY_USER_PREF_PREFIX
|
||||
import json
|
||||
|
||||
# 扫描所有匹配 user_pref:* 的 key
|
||||
pattern = f"{REDIS_KEY_USER_PREF_PREFIX}:*"
|
||||
keys = Redis.scan_keys(pattern)
|
||||
|
||||
# 按 account_id 分组
|
||||
# 直接返回所有 key 和原始 value
|
||||
result = {}
|
||||
for key in keys:
|
||||
# 解析 key 格式: user_pref:{account_id}:{category}
|
||||
parts = key.split(':')
|
||||
if len(parts) >= 3:
|
||||
account_id = parts[1]
|
||||
category = parts[2]
|
||||
|
||||
# 读取对应的值
|
||||
value = Redis.read(key)
|
||||
if value:
|
||||
try:
|
||||
vector = json.loads(value)
|
||||
if account_id not in result:
|
||||
result[account_id] = {}
|
||||
result[account_id][category] = {
|
||||
'key': key,
|
||||
'preference_vector': vector,
|
||||
'vector_length': len(vector)
|
||||
}
|
||||
except json.JSONDecodeError:
|
||||
# 如果 JSON 解析失败,保存原始值
|
||||
if account_id not in result:
|
||||
result[account_id] = {}
|
||||
result[account_id][category] = {
|
||||
'key': key,
|
||||
'raw_value': value,
|
||||
'error': 'JSON decode failed'
|
||||
}
|
||||
# 读取对应的值
|
||||
value = Redis.read(key)
|
||||
if value:
|
||||
result[key] = value
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from app.api import api_design_pre_processing
|
||||
from app.api import api_generate_image
|
||||
from app.api import api_mannequins_edit
|
||||
from app.api import api_pose_transform
|
||||
from app.api import api_precompute
|
||||
from app.api import api_prompt_generation
|
||||
from app.api import api_recommendation
|
||||
from app.api import api_test
|
||||
@@ -21,6 +22,7 @@ router.include_router(api_prompt_generation.router, tags=['prompt_generation'],
|
||||
router.include_router(api_design_pre_processing.router, tags=['design_pre_processing'], prefix="/api")
|
||||
router.include_router(api_brand_dna.router, tags=['api_brand_dna'], prefix="/api")
|
||||
router.include_router(api_recommendation.router, tags=['api_recommendation'], prefix="/api")
|
||||
router.include_router(api_precompute.router, tags=['api_precompute'], prefix="/api")
|
||||
router.include_router(api_mannequins_edit.router, tags=['api_mannequins_edit'], prefix="/api")
|
||||
router.include_router(api_pose_transform.router, tags=['api_pose_transform'], prefix="/api")
|
||||
router.include_router(api_clothing_seg.router, tags=['api_clothing_seg'], prefix="/api")
|
||||
|
||||
@@ -318,8 +318,8 @@ def precompute_system_sketch_vectors(batch_size: int = 1000, retry_times: int =
|
||||
def compute_user_preference_vector(
|
||||
account_id: int,
|
||||
category: str,
|
||||
conn: Optional[pymysql.connections.Connection] = None
|
||||
# max_date: Optional[datetime] = None
|
||||
conn: Optional[pymysql.connections.Connection] = None,
|
||||
max_date: Optional[datetime] = None
|
||||
) -> Optional[np.ndarray]:
|
||||
"""
|
||||
计算用户偏好向量
|
||||
@@ -519,16 +519,16 @@ def run_precompute():
|
||||
logger.info("=" * 50)
|
||||
|
||||
# 1. 优化数据库表结构
|
||||
logger.info("\n[1/5] 优化数据库表结构...")
|
||||
optimize_database_table()
|
||||
# logger.info("\n[1/5] 优化数据库表结构...")
|
||||
# optimize_database_table()
|
||||
|
||||
# # 2. 创建 Milvus 集合
|
||||
# logger.info("\n[2/5] 创建 Milvus 集合...")
|
||||
# create_collection()
|
||||
|
||||
# 3. 历史数据迁移
|
||||
logger.info("\n[3/5] 历史数据迁移...")
|
||||
migrate_historical_data()
|
||||
# logger.info("\n[3/5] 历史数据迁移...")
|
||||
# migrate_historical_data()
|
||||
|
||||
# # 4. 系统图向量预计算
|
||||
# logger.info("\n[4/5] 系统图向量预计算...")
|
||||
@@ -544,13 +544,13 @@ def run_precompute():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 1. 优化数据库表结构
|
||||
logger.info("\n[1/5] 优化数据库表结构...")
|
||||
optimize_database_table()
|
||||
|
||||
# 3. 历史数据迁移
|
||||
logger.info("\n[3/5] 历史数据迁移...")
|
||||
migrate_historical_data()
|
||||
# # 1. 优化数据库表结构
|
||||
# logger.info("\n[1/5] 优化数据库表结构...")
|
||||
# optimize_database_table()
|
||||
#
|
||||
# # 3. 历史数据迁移
|
||||
# logger.info("\n[3/5] 历史数据迁移...")
|
||||
# migrate_historical_data()
|
||||
|
||||
# 5. 初始用户偏好向量生成
|
||||
logger.info("\n[5/5] 初始用户偏好向量生成...")
|
||||
|
||||
Reference in New Issue
Block a user