AI记忆体 (AIMemory)¶
AIMemory ¶
Bases: BaseMemory
AI Memory (人工智能内存) 是机器人的主内存模块,负责存储和管理所有与知识图谱、文档存储和搜索相关的信息。
AI Memory is the main memory module of the robot, responsible for storing and managing all information related to the knowledge graph, document storage, and search operations.
Attributes:
| Name | Type | Description |
|---|---|---|
docs |
Optional[BaseDocStore]
|
文档存储模块,用于存储和检索文档。 | The document store module for storing and retrieving documents. |
top_k |
int
|
在向量检索时返回的最高k个结果的数量。The number of top results to return in vector searches. |
recall_strict |
bool
|
指定在回忆(检索)内容时是否采用严格模式。Specifies whether to use strict mode when recalling (retrieving) content. 在严格模式下,将严格遵守Token限制。| In strict mode, token limitations are strictly adhered to. |
kg_format |
Literal[...]
|
定义知识图谱节点输出的格式。 | Defines the format for the output of knowledge graph nodes. |
enable_kg_query_expansion |
bool
|
指定是否在进行知识图谱检索时使用当前会话中的历史记录来扩展检索。 | Specifies whether to use the history of the current session to expand searches when querying the knowledge graph. 这可以提高检索的 相关性,但可能增加执行时间。This can improve the relevance of the retrieval but may increase execution time. |
使用此类可以有效地管理和查询与机器人操作相关的各种信息资源,包括但不限于知识图谱数据和文档。
Notes
注意使用此模块时需要手动管理不同的数据源,比如要手动保证DocStore与Memos共用相同的存储,使用Memos召回的EleId会在DocStore进行查找。如果不保证一致性,可能会导致召回失败。 AIMemory的设计是使用分离式的存储设计,主要方便调试,同时可以方便拆卸与组合不同的Store以观察效果。但是在实际使用时,需要非常了解各个模块的作用与边界。
Using this class, various information resources related to robot operations, including but not limited to knowledge graph data and documents, can be effectively managed and queried.
validate_docs ¶
validate_docs() -> Self
Validate the docs field.
验证 docs 字段。
Source code in tfrobot/brain/memory/ai_memory.py
203 204 205 206 207 208 209 210 211 212 213 | |
recall ¶
recall(
current_input: UserAndAssMsg,
chunk_size: int | Annotated[list[int], Len(4, 4)],
length_function: Callable[[str], int],
exclude_str: Optional[str] = None,
) -> Tuple[
Optional[list[UserAndAssMsg]],
Optional[list[DocElement]],
Optional[str],
]
Recalls the content from memory based on the given natural language input.
根据给定的自然语言输入从内存中检索内容。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_input
|
str
|
The message user input. This is used to recall the content from memory. It is usually 用户输入的消息。用这个来从内存中回忆内容。通常由聊天输入历史记录格式化。 |
required |
chunk_size
|
Union[int, List[int]]
|
The size of the content to recall. It can be a single number or a list of numbers. If it is a list, the first number is the size of the conversation content to recall, the second number is the size of the memo content to recall, the third number is the size of the knowledge content to recall, and the fourth number is the size of the keyword content to recall. If it is a single number, it will be converted into four equal numbers. 要回忆的内容的大小。可以是单个数字或数字列表。如果是列表,第一个数字是要回忆的对话内容的大小,第二个数字是要回忆的备忘内容的大小, 第三个数字是要回忆的知识内容的大小,第四个数字是要回忆的关键字内容的大小。如果是单个数字,将被转换为四个相等的数字。 |
required |
length_function
|
Callable
|
A function to calculate the length of the content to recall. 用于计算所回忆内容长度的函数。 |
required |
exclude_str
|
Optional[str]
|
The string to exclude from the recall. Defaults to None. 要从回忆中排除的字符串。默认为 None。 |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Optional[list[UserAndAssMsg]], Optional[list[DocElement]], Optional[str]]
|
Tuple[Optional[list[BaseMessage]], Optional[list[DocElement]], Optional[str]]: The content recalled from memory. 分别是代表对话、文档元素和知识的内容。 |
Source code in tfrobot/brain/memory/ai_memory.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
async_recall
async
¶
async_recall(
current_input: UserAndAssMsg,
chunk_size: int | Annotated[list[int], Len(4, 4)],
length_function: Callable[[str], int],
exclude_str: Optional[str] = None,
) -> Tuple[
Optional[list[UserAndAssMsg]],
Optional[list[DocElement]],
Optional[str],
]
Recall方法的Async异步版本
Source code in tfrobot/brain/memory/ai_memory.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
commit ¶
commit(msg: UserAndAssMsg) -> None
Commits the chain result to memory.
将链结果提交到记忆中。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
UserAndAssMsg
|
The chain result to commit. 要提交的链结果。 |
required |
Source code in tfrobot/brain/memory/ai_memory.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
acommit
async
¶
acommit(msg: UserAndAssMsg) -> None
Commits the chain result to memory asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
UserAndAssMsg
|
The chain result to commit. |
required |
Source code in tfrobot/brain/memory/ai_memory.py
502 503 504 505 506 507 508 509 510 511 512 513 | |
sync_msg ¶
sync_msg(msg: UserAndAssMsg) -> None
通过 ConversationManager 路由到正确的 BufferStore,调用 buffer.sync_msg(msg)。
Source code in tfrobot/brain/memory/ai_memory.py
515 516 517 518 519 | |
async_sync_msg
async
¶
async_sync_msg(msg: UserAndAssMsg) -> None
sync_msg 的异步版本。
Source code in tfrobot/brain/memory/ai_memory.py
521 522 523 524 525 526 527 | |
get_platforms ¶
get_platforms() -> Sequence[tuple[PLATFORM_ID, str]] | None
AIMemory目前支持挂载单个ConversationManager
- DictBaseConversationManager不支持platform,因此返回None
- PGBaseConversationManager使用基于DPE的platform结构,因此返回查询结果
目前 get_platforms 还不是 BaseConversationManager 标准协议内容,因此在此会尝试使用动态获取属性的方法来判断是否可以使用
Returns:
| Type | Description |
|---|---|
Sequence[tuple[PLATFORM_ID, str]] | None
|
list[tuple[PLATFORM_ID, str]] | None: 注意可能返回空 |
Source code in tfrobot/brain/memory/ai_memory.py
529 530 531 532 533 534 535 536 537 538 539 540 541 | |
aget_platforms
async
¶
aget_platforms() -> (
Sequence[tuple[PLATFORM_ID, str]] | None
)
AIMemory目前支持挂载单个ConversationManager的异步版本
- DictBaseConversationManager不支持platform,因此返回None
- PGBaseConversationManager使用基于DPE的platform结构,因此返回查询结果
目前 get_platforms 还不是 BaseConversationManager 标准协议内容,因此在此会尝试使用动态获取属性的方法来判断是否可以使用
Returns:
| Type | Description |
|---|---|
Sequence[tuple[PLATFORM_ID, str]] | None
|
list[tuple[PLATFORM_ID, str]] | None: 注意可能返回空 |
Source code in tfrobot/brain/memory/ai_memory.py
543 544 545 546 547 548 549 550 551 552 553 554 555 | |
add_platform ¶
add_platform(platform_name: str) -> PLATFORM_ID
添加Platform,返回值为PlatformID | Add platform and return platform ID
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_name
|
str
|
Platform名称 | Platform name |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PLATFORM_ID |
PLATFORM_ID
|
PlatformID |
Source code in tfrobot/brain/memory/ai_memory.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
aadd_platform
async
¶
aadd_platform(platform_name: str) -> PLATFORM_ID
添加Platform,返回值为PlatformID | Add platform and return platform ID
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_name
|
str
|
Platform名称 | Platform name |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PLATFORM_ID |
PLATFORM_ID
|
PlatformID |
Source code in tfrobot/brain/memory/ai_memory.py
572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
update_platform ¶
update_platform(
platform_id: PLATFORM_ID, platform_name: str
) -> None
更新Platform名称 | Update platform name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_id
|
PLATFORM_ID
|
Platform的ID | Platform ID |
required |
platform_name
|
str
|
新的Platform名称 | New platform name |
required |
Source code in tfrobot/brain/memory/ai_memory.py
587 588 589 590 591 592 593 594 595 596 597 598 | |
aupdate_platform
async
¶
aupdate_platform(
platform_id: PLATFORM_ID, platform_name: str
) -> None
更新Platform名称 | Update platform name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_id
|
PLATFORM_ID
|
Platform的ID | Platform ID |
required |
platform_name
|
str
|
新的Platform名称 | New platform name |
required |
Source code in tfrobot/brain/memory/ai_memory.py
600 601 602 603 604 605 606 607 608 609 610 611 | |
delete_platform ¶
delete_platform(platform_id: PLATFORM_ID) -> None
删除Platform | Delete platform
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_id
|
PLATFORM_ID
|
要删除的Platform的ID | Platform ID to delete |
required |
Source code in tfrobot/brain/memory/ai_memory.py
613 614 615 616 617 618 619 620 621 622 623 | |
adelete_platform
async
¶
adelete_platform(platform_id: PLATFORM_ID) -> None
删除Platform | Delete platform
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_id
|
PLATFORM_ID
|
要删除的Platform的ID | Platform ID to delete |
required |
Source code in tfrobot/brain/memory/ai_memory.py
625 626 627 628 629 630 631 632 633 634 635 | |
get_conversations ¶
get_conversations(
cursor: Optional[str] = None,
count: Optional[int] = None,
platform_id: Optional[PLATFORM_ID] = None,
) -> tuple[list[tuple[CONVERSATION_KEY, str]], str]
Get all conversations from memory.
从记忆中获取所有对话。
因为会话排序随时有可能打乱,因此每次请求的时候指定一个初始位置是很有必要的。如此一来,前台可以获取到最新并且没有重复的对话。这里的最佳实践本来应该 使用游标,比如使用 update_timestamp * 1000 + id % 1000 生成游标。但我们系统并非专业的会话管理系统,其数据压力和数据量都不会过大,因此这里 不单独维护游标字段,而是直接让前台动态使用当前最后一个对话的ID作为游标。这样可以保证前台获取到的对话是最新的,且不会重复。如果有问题,刷新页面即可解决。
count支持负值,表示从后向前取数。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cursor
|
Optional[str]
|
The cursor to start from. | 起始游标 |
None
|
count
|
Optional[int]
|
The number of conversations to get. | 要获取的对话数量。 |
None
|
platform_id
|
Optional[int]
|
The platform id to filter conversations. | 要过滤的平台 ID。 |
None
|
Returns:
| Type | Description |
|---|---|
tuple[list[tuple[CONVERSATION_KEY, str]], str]
|
tuple[list[tuple[CONVERSATION_KEY, str]], str]: The conversations and the cursor. | 对话和游标。 |
Source code in tfrobot/brain/memory/ai_memory.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
aget_conversations
async
¶
aget_conversations(
cursor: Optional[str] = None,
count: Optional[int] = None,
platform_id: Optional[PLATFORM_ID] = None,
) -> tuple[list[tuple[CONVERSATION_KEY, str]], str]
Get all conversations from memory asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
664 665 666 667 668 669 670 671 | |
get_conversation ¶
get_conversation(
conversation_id: CONVERSATION_KEY,
) -> Optional[BaseBufferStore]
Get a conversation by its id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
CONVERSATION_KEY
|
The id of the conversation to get. | 要获取的会话的 ID。 |
required |
Returns:
| Type | Description |
|---|---|
Optional[BaseBufferStore]
|
Optional[BaseBufferStore]: The conversation buffer store. | 会话缓存存储。 |
Source code in tfrobot/brain/memory/ai_memory.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
aget_conversation
async
¶
aget_conversation(
conversation_id: CONVERSATION_KEY,
) -> Optional[BaseBufferStore]
Get a conversation by its id asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
688 689 690 691 692 693 | |
get_conversation_messages ¶
get_conversation_messages(
conversation_id: CONVERSATION_KEY,
page: int,
size: int,
type_include: Optional[list[str]] = None,
type_exclude: Optional[list[str]] = None,
role_include: Optional[list[str]] = None,
role_exclude: Optional[list[str]] = None,
filter_meta: Optional[
Callable[[Attributes], bool]
] = None,
) -> list[UserAndAssMsg]
Get messages from a conversation by conversation_manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int | str
|
The id/index of the conversation. | 对话的索引。 |
required |
page
|
int
|
The page number. | 页码。 |
required |
size
|
int
|
The size of the page. | 页的大小。 |
required |
type_include
|
Optional[list[str]]
|
The message types to include. | 要包含的消息类型。 |
None
|
type_exclude
|
Optional[list[str]]
|
The message types to exclude. | 要排除的消息类型。 |
None
|
role_include
|
Optional[list[str]]
|
The message roles to include. | 要包含的消息角色。 |
None
|
role_exclude
|
Optional[list[str]]
|
The message roles to exclude. | 要排除的消息角色。 |
None
|
filter_meta
|
Optional[Callable[[Attributes], bool]]
|
The function to filter messages by metadata. | 用于根据 元数据过滤消息的函数。 |
None
|
Returns:
| Type | Description |
|---|---|
list[UserAndAssMsg]
|
list[UserAndAssMsg]: The messages from the conversation. | 对话中的消息。 |
Source code in tfrobot/brain/memory/ai_memory.py
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
aget_conversation_messages
async
¶
aget_conversation_messages(
conversation_id: CONVERSATION_KEY,
page: int,
size: int,
type_include: Optional[list[str]] = None,
type_exclude: Optional[list[str]] = None,
role_include: Optional[list[str]] = None,
role_exclude: Optional[list[str]] = None,
filter_meta: Optional[
Callable[[Attributes], bool]
] = None,
) -> list[UserAndAssMsg]
Get messages from a conversation by conversation_manager asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |
get_latest_msg_from_conversation ¶
get_latest_msg_from_conversation(
conversation_id: CONVERSATION_KEY,
) -> Optional[UserAndAssMsg]
获取会话的最新消息
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int | str
|
The id/index of the conversation. | 对话的索引。 |
required |
Returns:
| Type | Description |
|---|---|
Optional[UserAndAssMsg]
|
Optional[UserAndAssMsg]: The latest message from the conversation. | 会话的最新消息。 |
Source code in tfrobot/brain/memory/ai_memory.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
aget_latest_msg_from_conversation
async
¶
aget_latest_msg_from_conversation(
conversation_id: CONVERSATION_KEY,
) -> Optional[UserAndAssMsg]
获取会话的最新消息
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
int | str
|
The id/index of the conversation. | 对话的索引。 |
required |
Returns:
| Type | Description |
|---|---|
Optional[UserAndAssMsg]
|
Optional[UserAndAssMsg]: The latest message from the conversation. | 会话的最新消息。 |
Source code in tfrobot/brain/memory/ai_memory.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
get_conversation_messages_by_cursor ¶
get_conversation_messages_by_cursor(
conversation_id: CONVERSATION_KEY,
count: int,
cursor: Optional[str] = None,
type_include: Optional[list[str]] = None,
type_exclude: Optional[list[str]] = None,
role_include: Optional[list[str]] = None,
role_exclude: Optional[list[str]] = None,
filter_meta: Optional[
Callable[[Attributes], bool]
] = None,
) -> tuple[list[UserAndAssMsg], str]
Get messages from a conversation by cursor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
CONVERSATION_KEY
|
The id of the conversation. | 会话的 ID。 |
required |
cursor
|
Optional[str]
|
The cursor to get messages. | 获取消息的游标。 |
None
|
count
|
int
|
The number of messages to get. | 要获取的消息数量。 |
required |
type_include
|
Optional[list[str]]
|
The message types to include. | 要包含的消息类型。 |
None
|
type_exclude
|
Optional[list[str]]
|
The message types to exclude. | 要排除的消息类型。 |
None
|
role_include
|
Optional[list[str]]
|
The message roles to include. | 要包含的消息角色。 |
None
|
role_exclude
|
Optional[list[str]]
|
The message roles to exclude. | 要排除的消息角色。 |
None
|
filter_meta
|
Optional[Callable[[Attributes], bool]]
|
The function to filter messages by metadata. | 用于根据 |
None
|
Returns:
| Type | Description |
|---|---|
tuple[list[UserAndAssMsg], str]
|
tuple[list[UserAndAssMsg], str]: The messages from the conversation and the cursor. | 对话中的消息和游标。 |
Source code in tfrobot/brain/memory/ai_memory.py
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
aget_conversation_messages_by_cursor
async
¶
aget_conversation_messages_by_cursor(
conversation_id: CONVERSATION_KEY,
count: int,
cursor: Optional[str] = None,
type_include: Optional[list[str]] = None,
type_exclude: Optional[list[str]] = None,
role_include: Optional[list[str]] = None,
role_exclude: Optional[list[str]] = None,
filter_meta: Optional[
Callable[[Attributes], bool]
] = None,
) -> tuple[list[UserAndAssMsg], str]
Get messages from a conversation by cursor asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
add_conversation ¶
add_conversation(
name: str, platform_id: Optional[PLATFORM_ID] = None
) -> CONVERSATION_KEY
Add a conversation to the memory.
是否需要传递platform_id,取决于具体的实现。建议尽可能都传。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the conversation. | 会话的名称。 |
required |
platform_id
|
Optional[int]
|
The platform id of the conversation. | 会话的平台 ID。 |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
CONVERSATION_KEY |
CONVERSATION_KEY
|
The key of the conversation. | 会话的键。 |
Source code in tfrobot/brain/memory/ai_memory.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | |
aadd_conversation
async
¶
aadd_conversation(
name: str, platform_id: Optional[PLATFORM_ID] = None
) -> CONVERSATION_KEY
Add a conversation asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
850 851 852 853 854 855 | |
update_conversation ¶
update_conversation(
conversation_id: CONVERSATION_KEY, name: str
) -> None
Update the name of a conversation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
CONVERSATION_KEY
|
The id of the conversation to update. | 要更新的会话的 ID。 |
required |
name
|
str
|
The new name of the conversation. | 会话的新名称。 |
required |
Source code in tfrobot/brain/memory/ai_memory.py
857 858 859 860 861 862 863 864 865 866 | |
aupdate_conversation
async
¶
aupdate_conversation(
conversation_id: CONVERSATION_KEY, name: str
) -> None
Update the name of a conversation asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
868 869 870 871 | |
delete_conversation ¶
delete_conversation(
conversation_id: CONVERSATION_KEY,
) -> None
Delete a conversation by its id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
CONVERSATION_KEY
|
The id of the conversation to delete. | 要删除的会话的 ID。 |
required |
Source code in tfrobot/brain/memory/ai_memory.py
873 874 875 876 877 878 879 880 881 | |
adelete_conversation
async
¶
adelete_conversation(
conversation_id: CONVERSATION_KEY,
) -> None
Delete a conversation asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
883 884 885 886 | |
get_docs ¶
get_docs(
page: Optional[int] = None,
size: Optional[int] = None,
keywords: Optional[list[str]] = None,
) -> list[Document]
Get documents from the memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
Optional[int]
|
The page number. | 页码。 |
None
|
size
|
Optional[int]
|
The size of the page. | 页的大小。 |
None
|
keywords
|
Optional[list[str]]
|
The keywords to search for. | 要搜索的关键字。 |
None
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
list[Document]: The documents from the memory. | 记忆中的文档。 |
Source code in tfrobot/brain/memory/ai_memory.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |
aget_docs
async
¶
aget_docs(
page: Optional[int] = None,
size: Optional[int] = None,
keywords: Optional[list[str]] = None,
) -> list[Document]
Get documents from the memory asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
907 908 909 910 911 912 913 914 | |
get_doc ¶
get_doc(doc_id: int) -> Document
Get a document by its id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_id
|
int
|
The id of the document to get. | 要获取的文档的 ID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Document |
Document
|
The document from the memory. | 记忆中的文档。 |
Source code in tfrobot/brain/memory/ai_memory.py
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 | |
aget_doc
async
¶
aget_doc(doc_id: int) -> Document
Get a document by its id asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
934 935 936 937 938 939 940 941 942 | |
add_doc ¶
add_doc(doc: Document) -> DocId
添加文档(已废弃——委托 :meth:upsert_doc)。
TFROB-389 [S4.1]:本方法发 DeprecationWarning 后委托给 :meth:upsert_doc。
新代码应直接调 :meth:upsert_doc(idempotent;含 memo 联动;同 file_uri 二次
调用走 reconcile 而非二次插入)。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
要添加的文档。 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DocId |
DocId
|
文档 ID( |
Source code in tfrobot/brain/memory/ai_memory.py
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | |
aadd_doc
async
¶
aadd_doc(doc: Document) -> DocId
:meth:add_doc 的异步镜像(已废弃——委托 :meth:aupsert_doc)。
Source code in tfrobot/brain/memory/ai_memory.py
964 965 966 967 968 969 970 971 972 | |
update_doc ¶
update_doc(doc: Document) -> None
更新文档(D20 / TFROB-410 convenience wrapper)。
从 doc.hash_strategy_uri 反构造 :class:HashStrategy,转发到 store 层 D20 新签名;
memo(向量库)侧的 element 增删同步语义保留。
.. note::
本方法是 convenience wrapper——签名隐藏了 D20 严签名所需的 strategy。
hot path 应改走 :meth:upsert_doc(已持有 doc 全量上下文,无额外 fetch 开销)。
Source code in tfrobot/brain/memory/ai_memory.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 | |
aupdate_doc
async
¶
aupdate_doc(doc: Document) -> None
异步更新文档(D20 / TFROB-411 async convenience wrapper)。
镜像同步 :meth:update_doc——从 doc.hash_strategy_uri 反构造 :class:HashStrategy,
转发到 store 层 D20 新签名;memo(向量库)侧的 element 增删同步语义保留。
.. note::
本方法是 convenience wrapper——签名隐藏了 D20 严签名所需的 strategy。
hot path 应改走 :meth:upsert_doc(已持有 doc 全量上下文,无额外 fetch 开销)。
Source code in tfrobot/brain/memory/ai_memory.py
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
upsert_doc ¶
upsert_doc(new_doc: Document) -> UpsertResult
文档级 reconcile(PRD §5.3.1 命名澄清——表面 upsert,实质 reconcile_doc)。
前置契约:new_doc 已经过 loader 出口 :meth:HashStrategy.attach,三层 hash +
seq_in_page 全填好。不得在本入口再调 attach(重复计算且与"DB 是权威"原则冲突)。
TFROB-416 [S3.6.4] memo 联动¶
若 self.memos 非空,本方法在 doc-store 事务前后做 snapshot diff:
- 事务前:按
file_urisnapshotold_ele_ids: set[int] - 事务内:跑 4 短路 + 两段式 LCS + 4 收尾(同 TFROB-414/415 主流程)
- 事务后:
new_ele_ids = {e.ele_id for e in new_doc.elements if e.ele_id is not None}→removed = old - new/added_eles = new_doc.elements where ele_id in (new - old)→memo.deletes(removed)+memo.adds(added_eles)同步触发,每 memo 独立调用
关键约束(PRD Q3 / Q4):
- nochange 路径(
status="unchanged"):elements_added == 0 == elements_removed→ memo 0 调用(不写孤儿) - EQUAL / sync 路径:ele_id 透传 →
new - old = ∅&old - new = ∅→ memo 0 调用 - INSERT N + DELETE M:memo 精确 +N -M(多 memo 时每个独立 deletes/adds)
memo 调用走 transaction 边界外——避免事务内长时间持锁(向量库 IO 可能慢)。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_doc
|
Document
|
Pydantic :class: |
required |
Returns:
| Type | Description |
|---|---|
UpsertResult
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
若 |
Note
底层 store 异常会触发 transaction() rollback 后向上传播;memo 异常不会
回滚 doc-store 事务(已 commit),按现有 :meth:delete_doc / :meth:add_doc
行为契约——memo 仅作 best-effort 联动,调用方需自行兜底重试。
Source code in tfrobot/brain/memory/ai_memory.py
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 | |
aupsert_doc
async
¶
aupsert_doc(new_doc: Document) -> UpsertResult
:meth:upsert_doc 的异步镜像(TFROB-414 [S3.6.2] + TFROB-416 [S3.6.4] memo 联动)。
memo 联动语义详见 :meth:upsert_doc docstring;事务前/后 snapshot 与同步调用契约一致。
memo 协议本身仅暴露 sync adds / deletes——异步路径直接调 sync 方法(向量库写入
通常是本地 / fast remote IO,不需异步)。
Source code in tfrobot/brain/memory/ai_memory.py
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 | |
delete_doc ¶
delete_doc(doc_id: int) -> None
删除文档(已废弃——同步 memos 后落到 store 层)。
TFROB-389 [S4.1]:本方法发 DeprecationWarning 后保留旧实现(同步清 memos +
self.docs.delete_doc)。upsert_doc 是 reconcile 语义,不包含"按 doc_id 整删"
——若调用方真要删除,应直接调 self.docs.delete_doc 并自行处理 memo 同步。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc_id
|
int
|
要删除的文档 ID。 |
required |
Source code in tfrobot/brain/memory/ai_memory.py
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 | |
adelete_doc
async
¶
adelete_doc(doc_id: int) -> None
:meth:delete_doc 的异步镜像(已废弃)。
Source code in tfrobot/brain/memory/ai_memory.py
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 | |
get_pages ¶
get_pages(
page: Optional[int],
size: Optional[int],
keywords: Optional[list[str]],
doc_ids: Optional[list[int]],
) -> list[DocPage]
Get pages from the memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
Optional[int]
|
The page number. | 页码。 |
required |
size
|
Optional[int]
|
The size of the page. | 页的大小。 |
required |
keywords
|
Optional[list[str]]
|
The keywords to search for. | 要搜索的关键字。 |
required |
doc_ids
|
Optional[list[int]]
|
The document ids to search for. | 要搜索的文档 ID。 |
required |
Returns:
| Type | Description |
|---|---|
list[DocPage]
|
list[DocPage]: The pages from the memory. | 记忆中的页面。 |
Source code in tfrobot/brain/memory/ai_memory.py
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 | |
aget_pages
async
¶
aget_pages(
page: Optional[int],
size: Optional[int],
keywords: Optional[list[str]],
doc_ids: Optional[list[int]],
) -> list[DocPage]
Get pages from the memory asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
1769 1770 1771 1772 1773 1774 1775 1776 | |
get_page ¶
get_page(page_id: int) -> DocPage
Get a page by its id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page_id
|
int
|
The id of the page to get. | 要获取的页面的 ID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DocPage |
DocPage
|
The page from the memory. | 记忆中的页面。 |
Source code in tfrobot/brain/memory/ai_memory.py
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 | |
aget_page
async
¶
aget_page(page_id: int) -> DocPage
Get a page by its id asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
1796 1797 1798 1799 1800 1801 1802 1803 1804 | |
add_page ¶
add_page(page: DocPage) -> PageId
Add a page to the memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
DocPage
|
The page to add. | 要添加的页面。 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PageId |
PageId
|
The id of the page. | 页面的 ID。 |
Source code in tfrobot/brain/memory/ai_memory.py
1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 | |
aadd_page
async
¶
aadd_page(page: DocPage) -> PageId
Add a page to the memory asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
1821 1822 1823 1824 1825 1826 | |
update_page ¶
update_page(page: DocPage) -> None
更新页面(D-2 简化签名 / TFROB-455 thin wrapper)。
TFROB-455:D20 fetch 全树 + 反构造 strategy 已下沉到 docs.update_page 简单签名 public,
本方法只负责 memo 侧 element 增删同步 + 单调转发。hot path 应改走 :meth:upsert_doc。
Source code in tfrobot/brain/memory/ai_memory.py
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 | |
aupdate_page
async
¶
aupdate_page(page: DocPage) -> None
异步更新页面(D-2 简化签名 / TFROB-455 thin wrapper)。
与 :meth:update_page 异步对称。
Source code in tfrobot/brain/memory/ai_memory.py
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 | |
delete_page ¶
delete_page(page_id: int) -> None
Delete a page by its id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page_id
|
int
|
The id of the page to delete. | 要删除的页面的 ID. |
required |
Source code in tfrobot/brain/memory/ai_memory.py
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 | |
adelete_page
async
¶
adelete_page(page_id: int) -> None
Delete a page by its id asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 | |
get_elements ¶
get_elements(
page: Optional[int],
size: Optional[int],
keywords: Optional[list[str]],
page_ids: Optional[list[int]],
) -> list[DocElement]
Get all elements from memory.
从记忆中获取所有元素。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
Optional[int]
|
The page number. |
required |
size
|
Optional[int]
|
The size of the page. |
required |
keywords
|
Optional[list[str]]
|
The keywords to search for. |
required |
page_ids
|
Optional[list[int]]
|
The page ids to search for. |
required |
Returns:
| Type | Description |
|---|---|
list[DocElement]
|
list[DocElement]: The list of all elements. |
Source code in tfrobot/brain/memory/ai_memory.py
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 | |
get_element ¶
get_element(element_id: int) -> DocElement
Get a DocElement by its id.
通过element_id获取DocElement
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_id
|
int
|
|
required |
Returns:
| Type | Description |
|---|---|
DocElement
|
DocElement |
Source code in tfrobot/brain/memory/ai_memory.py
1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 | |
aget_element
async
¶
aget_element(element_id: int) -> DocElement
Get a DocElement by its id asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
1955 1956 1957 1958 1959 1960 1961 1962 1963 | |
add_element ¶
add_element(element: DocElement) -> EleId
Add a DocElement to memory.
添加DocElement 返回element_id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
DocElement
|
|
required |
Returns:
| Type | Description |
|---|---|
EleId
|
int |
Source code in tfrobot/brain/memory/ai_memory.py
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 | |
aadd_element
async
¶
aadd_element(element: DocElement) -> EleId
Add a DocElement to memory asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 | |
update_element ¶
update_element(element: DocElement) -> None
更新元素(D-2 简化签名 / TFROB-455 thin wrapper)。
TFROB-455:fetch 全树 + 反构造 strategy 已下沉到 docs.update_element 简单签名 public,
本方法只负责单调转发 + memo 侧同步。hot path 应改走 :meth:upsert_doc(已持有 doc 全量上下文)。
Source code in tfrobot/brain/memory/ai_memory.py
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 | |
aupdate_element
async
¶
aupdate_element(element: DocElement) -> None
异步更新元素(D-2 简化签名 / TFROB-455 thin wrapper)。
与 :meth:update_element 异步对称。
Source code in tfrobot/brain/memory/ai_memory.py
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 | |
delete_element ¶
delete_element(element_id: int) -> None
Delete a DocElement by its id.
删除DocElement
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_id
|
int
|
|
required |
Source code in tfrobot/brain/memory/ai_memory.py
2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 | |
adelete_element
async
¶
adelete_element(element_id: int) -> None
Delete a DocElement by its id asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2050 2051 2052 2053 2054 2055 2056 2057 | |
add_graph_cls ¶
add_graph_cls(
class_iri: CLS_IRI,
super_classes: Optional[list[str]] = None,
annotations: Optional[dict] = None,
) -> CLS_IRI
Add a new class to the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_iri
|
str
|
class iri | 类的IRI |
required |
super_classes
|
Optional[list[str]]
|
super classes | 父类 |
None
|
annotations
|
Optional[dict]
|
annotations | 注解 |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
CLS_IRI
|
class iri | 类的IRI |
Source code in tfrobot/brain/memory/ai_memory.py
2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 | |
aadd_graph_cls
async
¶
aadd_graph_cls(
class_iri: CLS_IRI,
super_classes: Optional[list[str]] = None,
annotations: Optional[dict] = None,
) -> CLS_IRI
Add a new class to the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2078 2079 2080 2081 2082 2083 | |
update_graph_cls ¶
update_graph_cls(
class_iri: CLS_IRI,
new_super_classes: Optional[list[str]] = None,
new_annotations: Optional[dict] = None,
) -> None
Update a class in the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_iri
|
str
|
class iri | 类的IRI |
required |
new_super_classes
|
Optional[list[str]]
|
new super classes | 新的父类 |
None
|
new_annotations
|
Optional[dict]
|
new annotations | 新的注解 |
None
|
Source code in tfrobot/brain/memory/ai_memory.py
2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 | |
aupdate_graph_cls
async
¶
aupdate_graph_cls(
class_iri: CLS_IRI,
new_super_classes: Optional[list[str]] = None,
new_annotations: Optional[dict] = None,
) -> None
Update a class in the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2099 2100 2101 2102 2103 2104 | |
delete_graph_cls ¶
delete_graph_cls(class_iri: CLS_IRI) -> None
Delete a class from the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_iri
|
str
|
class iri | 类的IRI |
required |
Source code in tfrobot/brain/memory/ai_memory.py
2106 2107 2108 2109 2110 2111 2112 2113 2114 | |
adelete_graph_cls
async
¶
adelete_graph_cls(class_iri: CLS_IRI) -> None
Delete a class from the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2116 2117 2118 2119 | |
add_graph_property ¶
add_graph_property(
property_iri: PROP_IRI,
property_type: Literal["object", "data"],
domain: Optional[list[CLS_IRI]] = None,
o_range: Optional[list] = None,
is_functional: bool = False,
is_inverse_functional: bool = False,
is_symmetric: bool = False,
is_transitive: bool = False,
is_asymmetric: bool = False,
is_reflexive: bool = False,
is_irreflexive: bool = False,
trigger_words: Optional[list[str]] = None,
) -> PROP_IRI
Add a new property to the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_iri
|
PROP_IRI
|
property iri | 属性的IRI |
required |
property_type
|
Literal['object', 'data']
|
property type | 属性类型 |
required |
domain
|
Optional[list[str]]
|
domain | 领域 |
None
|
o_range
|
Optional[list]
|
range | 范围 |
None
|
is_functional
|
bool
|
is functional | 是否是功能性的 |
False
|
is_inverse_functional
|
bool
|
is inverse functional | 是否是反功能性的 |
False
|
is_symmetric
|
bool
|
is symmetric | 是否是对 |
False
|
is_transitive
|
bool
|
is transitive | 是否是传递性的 |
False
|
is_asymmetric
|
bool
|
is asymmetric | 是否是非对称的 |
False
|
is_reflexive
|
bool
|
is reflexive | 是否是自反的 |
False
|
is_irreflexive
|
bool
|
is irreflexive | 是否是非自反的 |
False
|
trigger_words
|
Optional[list[str]]
|
trigger words | 触发词 |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
PROP_IRI
|
property iri | 属性的IRI |
Source code in tfrobot/brain/memory/ai_memory.py
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 | |
aadd_graph_property
async
¶
aadd_graph_property(
property_iri: PROP_IRI,
property_type: Literal["object", "data"],
domain: Optional[list[CLS_IRI]] = None,
o_range: Optional[list] = None,
is_functional: bool = False,
is_inverse_functional: bool = False,
is_symmetric: bool = False,
is_transitive: bool = False,
is_asymmetric: bool = False,
is_reflexive: bool = False,
is_irreflexive: bool = False,
trigger_words: Optional[list[str]] = None,
) -> PROP_IRI
Add a new property to the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 | |
update_graph_property ¶
update_graph_property(
property_iri: PROP_IRI,
domain: Optional[list[CLS_IRI]] = None,
o_range: Optional[list] = None,
is_functional: Optional[bool] = None,
is_inverse_functional: Optional[bool] = None,
is_symmetric: Optional[bool] = None,
is_transitive: Optional[bool] = None,
is_asymmetric: Optional[bool] = None,
is_reflexive: Optional[bool] = None,
is_irreflexive: Optional[bool] = None,
trigger_words: Optional[list[str]] = None,
) -> None
Update a property in the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_iri
|
str
|
property iri | 属性的IRI |
required |
domain
|
Optional[list[str]]
|
domain | 领域 |
None
|
o_range
|
Optional[list]
|
range | 范围 |
None
|
is_functional
|
Optional[bool]
|
is functional | 是否是功能性的 |
None
|
is_inverse_functional
|
Optional[bool]
|
is inverse functional | 是否是反功能性的 |
None
|
is_symmetric
|
Optional[bool]
|
is symmetric | 是否是对 |
None
|
is_transitive
|
Optional[bool]
|
is transitive | 是否是传递性的 |
None
|
is_asymmetric
|
Optional[bool]
|
is asymmetric | 是否是非对称的 |
None
|
is_reflexive
|
Optional[bool]
|
is reflexive | 是否是自反的 |
None
|
is_irreflexive
|
Optional[bool]
|
is irreflexive | 是否是非自反的 |
None
|
trigger_words
|
Optional[list[str]]
|
trigger words | 触发词 |
None
|
Source code in tfrobot/brain/memory/ai_memory.py
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 | |
aupdate_graph_property
async
¶
aupdate_graph_property(
property_iri: PROP_IRI,
domain: Optional[list[CLS_IRI]] = None,
o_range: Optional[list] = None,
is_functional: Optional[bool] = None,
is_inverse_functional: Optional[bool] = None,
is_symmetric: Optional[bool] = None,
is_transitive: Optional[bool] = None,
is_asymmetric: Optional[bool] = None,
is_reflexive: Optional[bool] = None,
is_irreflexive: Optional[bool] = None,
trigger_words: Optional[list[str]] = None,
) -> None
Update a property in the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 | |
delete_graph_property ¶
delete_graph_property(property_iri: PROP_IRI) -> None
Delete a property from the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_iri
|
str
|
property iri | 属性的IRI |
required |
Source code in tfrobot/brain/memory/ai_memory.py
2281 2282 2283 2284 2285 2286 2287 2288 2289 | |
adelete_graph_property
async
¶
adelete_graph_property(property_iri: PROP_IRI) -> None
Delete a property from the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2291 2292 2293 2294 | |
add_graph_entity ¶
add_graph_entity(cls_iri: CLS_IRI, info: dict) -> IND_IRI
Add a new entity to the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls_iri
|
str
|
class iri | 类的IRI |
required |
info
|
dict
|
entity info | 实体信息 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
IND_IRI
|
entity iri | 实体的IRI |
Source code in tfrobot/brain/memory/ai_memory.py
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 | |
aadd_graph_entity
async
¶
aadd_graph_entity(cls_iri: CLS_IRI, info: dict) -> IND_IRI
Add a new entity to the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2312 2313 2314 2315 | |
update_graph_entity ¶
update_graph_entity(
entity_iri: IND_IRI, info: dict
) -> None
Update an entity in the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_iri
|
str
|
entity iri | 实体的IRI |
required |
info
|
dict
|
entity info | 实体信息 |
required |
Source code in tfrobot/brain/memory/ai_memory.py
2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 | |
aupdate_graph_entity
async
¶
aupdate_graph_entity(
entity_iri: IND_IRI, info: dict
) -> None
Update an entity in the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2328 2329 2330 2331 | |
delete_graph_entity ¶
delete_graph_entity(entity_iri: IND_IRI) -> None
Delete an entity from the graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_iri
|
str
|
entity iri | 实体的IRI |
required |
Source code in tfrobot/brain/memory/ai_memory.py
2333 2334 2335 2336 2337 2338 2339 2340 2341 | |
adelete_graph_entity
async
¶
adelete_graph_entity(entity_iri: IND_IRI) -> None
Delete an entity from the graph database asynchronously.
Source code in tfrobot/brain/memory/ai_memory.py
2343 2344 2345 2346 | |
get_graph_cls ¶
get_graph_cls(class_iri: CLS_IRI) -> Optional[ThingClass]
获取指定类的详细信息。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_iri
|
CLS_IRI
|
类的IRI。 |
required |
Returns:
| Type | Description |
|---|---|
Optional[ThingClass]
|
Optional[ThingClass]: 类的详细信息。 |
Source code in tfrobot/brain/memory/ai_memory.py
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 | |
aget_graph_cls
async
¶
aget_graph_cls(class_iri: CLS_IRI) -> Optional[ThingClass]
获取指定类的详细信息。
Source code in tfrobot/brain/memory/ai_memory.py
2362 2363 2364 2365 | |
get_all_graph_clses ¶
get_all_graph_clses() -> list[ThingClass]
获取所有类的详细信息。
Returns:
| Type | Description |
|---|---|
list[ThingClass]
|
list[ThingClass]: 所有类的详细信息。 |
Source code in tfrobot/brain/memory/ai_memory.py
2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 | |
aget_all_graph_clses
async
¶
aget_all_graph_clses() -> list[ThingClass]
获取所有类的详细信息。
Source code in tfrobot/brain/memory/ai_memory.py
2378 2379 2380 2381 | |
get_graph_property ¶
get_graph_property(
property_iri: PROP_IRI,
) -> Optional[PropertyClass]
获取指定属性的详细信息。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_iri
|
PROP_IRI
|
属性的IRI。 |
required |
Returns:
| Type | Description |
|---|---|
Optional[PropertyClass]
|
Optional[PropertyClass]: 属性的详细信息。 |
Source code in tfrobot/brain/memory/ai_memory.py
2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 | |
aget_graph_property
async
¶
aget_graph_property(
property_iri: PROP_IRI,
) -> Optional[PropertyClass]
获取指定属性的详细信息。
Source code in tfrobot/brain/memory/ai_memory.py
2397 2398 2399 2400 | |
get_all_graph_properties ¶
get_all_graph_properties(
prop_type: Optional[
Literal["object", "data", "annotation"]
] = None,
) -> list[PropertyClass]
获取所有属性的详细信息。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prop_type
|
Optional[Literal['object', 'data', 'annotation']]
|
属性的类型。 |
None
|
Returns:
| Type | Description |
|---|---|
list[PropertyClass]
|
list[PropertyClass]: 所有属性的详细信息。 |
Source code in tfrobot/brain/memory/ai_memory.py
2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 | |
aget_all_graph_properties
async
¶
aget_all_graph_properties(
prop_type: Optional[
Literal["object", "data", "annotation"]
] = None,
) -> list[PropertyClass]
获取所有属性的详细信息。
Source code in tfrobot/brain/memory/ai_memory.py
2426 2427 2428 2429 2430 2431 | |
get_graph_entity ¶
get_graph_entity(entity_iri: IND_IRI) -> Optional[Thing]
获取指定实体的详细信息。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_iri
|
IND_IRI
|
实体的IRI。 |
required |
Returns:
| Type | Description |
|---|---|
Optional[Thing]
|
Optional[Thing]: 实体的详细信息。 |
Source code in tfrobot/brain/memory/ai_memory.py
2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 | |
aget_graph_entity
async
¶
aget_graph_entity(entity_iri: IND_IRI) -> Optional[Thing]
获取指定实体的详细信息。
Source code in tfrobot/brain/memory/ai_memory.py
2447 2448 2449 2450 | |
get_graph_entities_by_cls ¶
get_graph_entities_by_cls(cls_iri: CLS_IRI) -> list[Thing]
获取指定类的所有实体。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls_iri
|
CLS_IRI
|
类的IRI。 |
required |
Returns:
| Type | Description |
|---|---|
list[Thing]
|
list[Thing]: 指定类的所有实体。 |
Source code in tfrobot/brain/memory/ai_memory.py
2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 | |
aget_graph_entities_by_cls
async
¶
aget_graph_entities_by_cls(cls_iri: CLS_IRI) -> list[Thing]
获取指定类的所有实体。
Source code in tfrobot/brain/memory/ai_memory.py
2468 2469 2470 2471 | |
get_all_graph_entities ¶
get_all_graph_entities() -> list[Thing]
获取所有实体的详细信息。
Returns:
| Type | Description |
|---|---|
list[Thing]
|
list[Thing]: 所有实体的详细信息。 |
Source code in tfrobot/brain/memory/ai_memory.py
2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 | |
aget_all_graph_entities
async
¶
aget_all_graph_entities() -> list[Thing]
获取所有实体的详细信息。
Source code in tfrobot/brain/memory/ai_memory.py
2487 2488 2489 2490 | |
dispose ¶
dispose() -> None
释放 AIMemory 持有的所有子资源。每个子组件独立 try/except,互不影响。
Source code in tfrobot/brain/memory/ai_memory.py
2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 | |
adispose
async
¶
adispose() -> None
异步释放 AIMemory 持有的所有子资源。每个子组件独立 try/except,互不影响。
Source code in tfrobot/brain/memory/ai_memory.py
2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 | |