海马 OR映射

所有的数据库与对象的关系映射都是在type.properties文件定义中完成的。

他通常存放在HopObject目录的下面,名称固定。

 

具体在这个类型映射文件中定义的字段如下:


_db = dbname    //数据库名称,同db.properties

 

_table = TABLENAME   //当前对象映射的数据表名称

 

_id = ID_COLUMN    //对象id相当于表的主键

 

_name = NAME_COLUMN   //可选属性  当对象为“用户”时,该属性指定表中对应的用户名

 

_extends = parenttype      //继承另一原型的映射,不知何用

 

//翻译了半天才弄明白,此声明是某个集合字段,里面以逗号分隔存储某对象的id,有待实践

_parent = property1, property2.collectionX, root.collectionY

 

//特别,特别不好解释的一个,据我理解是扩展原型用的,索引某个存储着原型定义的字段
_prototype = PROTO_COLUMN

 

 

简单的映射举例:

属性    =  字段

prop1 = DB_COLUMN_1
prop2 = DB_COLUMN_2

 

属性参数  =  值
prop1.readonly = true     //只读,保护此字段数据不被写入数据库
prop1.private = true       //私有属性,js里默认是为public

 

一个引用其他对象的属性关联: One on One

prop3 = object (protoype)   //括号里面是另一个对象的名字
prop3.local = LOCAL_DB_COLUMN    //这里是prop3所在表中存储引用对象的id字段
prop3.foreign = FOREIGN_DB_COLUMN  //这是引用对象的表和字段,这俩写法都是 table.column

 

 

我们是不是应该先修改这个啊?# conscious_memory.py import time import logging from collections import defaultdict from typing import List, Dict, Any class MemorySystem: """记忆系统 - 负责信息的存储和检索""" def __init__(self): self.logger = logging.getLogger('MemorySystem') self.memories = [] self.memory_index = defaultdict(list) def store(self, content: Dict, tags: List[str] = None): """存储记忆""" memory_entry = { "id": f"mem_{int(time.time() * 1000)}", "content": content, "timestamp": time.time(), "tags": tags or [], "retrieval_count": 0 } self.memories.append(memory_entry) # 索引标签 for tag in memory_entry["tags"]: self.memory_index[tag].append(memory_entry["id"]) self.logger.info(f"存储新记忆: {content.get('type')} (标签: {', '.join(tags) if tags else '无'})") def retrieve(self, context: Dict, affective_state: Dict) -> List[Dict]: """检索相关记忆""" # 简化的检索逻辑 - 实际应使用向量搜索 query_tags = [] if "type" in context: query_tags.append(context["type"]) if "source" in context: query_tags.append(context["source"]) # 添加情感标签 emotion = affective_state["emotion"]["current_emotion"] if emotion != "neutral": query_tags.append(emotion) # 从索引中查找 results = [] for tag in query_tags: for mem_id in self.memory_index.get(tag, []): memory = next((m for m in self.memories if m["id"] == mem_id), None) if memory: memory["retrieval_count"] += 1 results.append(memory) # 按检索次数排序(简单相关性) results.sort(key=lambda x: x["retrieval_count"], reverse=True) return results[:5] # 返回最多5个相关记忆 def get_stats(self) -> Dict: """获取记忆系统统计信息""" return { "total_memories": len(self.memories), "tag_distribution": {tag: len(ids) for tag, ids in self.memory_index.items()}, "avg_retrieval": sum(m["retrieval_count"] for m in self.memories) / len( self.memories) if self.memories else 0 }
最新发布
08-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值