langchain_community.memory.kg
.ConversationKGMemory¶
- class langchain_community.memory.kg.ConversationKGMemory[源代码]¶
继承自:
BaseChatMemory
知识图谱会话内存。
与外部知识图谱集成,用于存储和检索会话中知识三元组的信息。
- 参数 ai_prefix: str = 'AI'¶
- 参数 chat_memory: BaseChatMessageHistory [可选]¶
- param entity_extraction_prompt: BasePromptTemplate = PromptTemplate(input_variables=['history', 'input'], template='You are an AI assistant reading the transcript of a conversation between an AI and a human. Extract all of the proper nouns from the last line of conversation. As a guideline, a proper noun is generally capitalized. You should definitely extract all names and places.\n\nThe conversation history is provided just in case of a coreference (e.g. "What do you know about him" where "him" is defined in a previous line) -- ignore items mentioned there that are not in the last line.\n\nReturn the output as a single comma-separated list, or NONE if there is nothing of note to return (e.g. the user is just issuing a greeting or having a simple conversation).\n\nEXAMPLE\nConversation history:\nPerson #1: how\'s it going today?\nAI: "It\'s going great! How about you?"\nPerson #1: good! busy working on Langchain. lots to do.\nAI: "That sounds like a lot of work! What kind of things are you doing to make Langchain better?"\nLast line:\nPerson #1: i\'m trying to improve Langchain\'s interfaces, the UX, its integrations with various products the user might want ... a lot of stuff.\nOutput: Langchain\nEND OF EXAMPLE\n\nEXAMPLE\nConversation history:\nPerson #1: how\'s it going today?\nAI: "It\'s going great! How about you?"\nPerson #1: good! busy working on Langchain. lots to do.\nAI: "That sounds like a lot of work! What kind of things are you doing to make Langchain better?"\nLast line:\nPerson #1: i\'m trying to improve Langchain\'s interfaces, the UX, its integrations with various products the user might want ... a lot of stuff. I\'m working with Person #2.\nOutput: Langchain, Person #2\nEND OF EXAMPLE\n\nConversation history (for reference only):\n{history}\nLast line of conversation (for extraction):\nHuman: {input}\n\nOutput:')¶
- 参数 human_prefix: str = 'Human'¶
- 参数 input_key: Optional[str] = None¶
- 参数 k: int = 2¶
- 参数 kg: NetworkxEntityGraph [可选]¶
- param knowledge_extraction_prompt: BasePromptTemplate = PromptTemplate(input_variables=['history', 'input'], template="You are a networked intelligence helping a human track knowledge triples about all relevant people, things, concepts, etc. and integrating them with your knowledge stored within your weights as well as that stored in a knowledge graph. Extract all of the knowledge triples from the last line of conversation. A knowledge triple is a clause that contains a subject, a predicate, and an object. The subject is the entity being described, the predicate is the property of the subject that is being described, and the object is the value of the property.\n\nEXAMPLE\nConversation history:\nPerson #1: Did you hear aliens landed in Area 51?\nAI: No, I didn't hear that. What do you know about Area 51?\nPerson #1: It's a secret military base in Nevada.\nAI: What do you know about Nevada?\nLast line of conversation:\nPerson #1: It's a state in the US. It's also the number 1 producer of gold in the US.\n\nOutput: (Nevada, is a, state)<|>(Nevada, is in, US)<|>(Nevada, is the number 1 producer of, gold)\nEND OF EXAMPLE\n\nEXAMPLE\nConversation history:\nPerson #1: Hello.\nAI: Hi! How are you?\nPerson #1: I'm good. How are you?\nAI: I'm good too.\nLast line of conversation:\nPerson #1: I'm going to the store.\n\nOutput: NONE\nEND OF EXAMPLE\n\nEXAMPLE\nConversation history:\nPerson #1: What do you know about Descartes?\nAI: Descartes was a French philosopher, mathematician, and scientist who lived in the 17th century.\nPerson #1: The Descartes I'm referring to is a standup comedian and interior designer from Montreal.\nAI: Oh yes, He is a comedian and an interior designer. He has been in the industry for 30 years. His favorite food is baked bean pie.\nLast line of conversation:\nPerson #1: Oh huh. I know Descartes likes to drive antique scooters and play the mandolin.\nOutput: (Descartes, likes to drive, antique scooters)<|>(Descartes, plays, mandolin)\nEND OF EXAMPLE\n\nConversation history (for reference only):\n{history}\nLast line of conversation (for extraction):\nHuman: {input}\n\nOutput:")¶
- 参数 llm: BaseLanguageModel [必需]¶
- param output_key: Optional[str] = None¶
- param return_messages: bool = False¶
- param summary_message_cls: Type[BaseMessage] = <class 'langchain_core.messages.system.SystemMessage'>¶
在上下文中包含的前述对话数量。
- async aclear() None ¶
清除内存内容。
- 返回类型
None
- async aload_memory_variables(inputs: Dict[str, Any]) Dict[str, Any] ¶
根据给定给链的文本输入异步返回键值对。
- 参数
inputs (Dict[str, Any]) – 链的输入。
- 返回
键值对字典。
- 返回类型
Dict[str, Any]
- async asave_context(inputs: Dict[str, Any], outputs: Dict[str, str]) None ¶
将此对话的上下文保存到缓冲区。
- 参数
输入 (Dict[str, Any]) –
输出 (Dict[str, str]) –
- 返回类型
None
- get_knowledge_triplets(input_string: str) List[KnowledgeTriple] [source]¶
- 参数
输入字符串 (str) –
- 返回类型
List[KnowledgeTriple]