results=client.agent_engines.retrieve_memories(name=agent_engine.api_resource.name,scope=SCOPE,similarity_search_params={"search_query":"QUERY",# Optional. Defaults to 3."top_k":3})# RetrieveMemories returns a pager. You can use `list` to retrieve all memories.list(results)"""Returns:[ RetrieveMemoriesResponseRetrievedMemory( memory=Memory( name="projects/.../locations/.../reasoningEngines/.../memories/...", ... fact="This is a fact." }, distance=0.5 ), RetrieveMemoriesResponseRetrievedMemory( memory=Memory( name="projects/.../locations/.../reasoningEngines/.../memories/...", ... fact="This is another fact." }, distance=0.7 ),]"""
results=client.agent_engines.retrieve_memories(name=agent_engine.api_resource.name,scope=SCOPE)# RetrieveMemories returns a pager. You can use `list` to retrieve all pages' memories.list(results)"""Returns:[ RetrieveMemoriesResponseRetrievedMemory( memory=Memory( name="projects/.../locations/.../reasoningEngines/.../memories/...", ... fact="This is a fact." } ), RetrieveMemoriesResponseRetrievedMemory( memory=Memory( name="projects/.../locations/.../reasoningEngines/.../memories/...", ... fact="This is another fact." } ),]"""
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Fetch memories\n\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page describes how to fetch generated and uploaded memories from Memory Bank. For the entire workflow of configuring, generating, and using Memory Bank, see the [Quickstart with REST API](/vertex-ai/generative-ai/docs/agent-engine/memory-bank/quickstart-api).\n| **Note:** If you [configured an Agent Development Kit agent](/vertex-ai/generative-ai/docs/agent-engine/memory-bank/quickstart-adk) to use Memory Bank, the agent orchestrates calls to `RetrieveMemories` for you, so you don't need to make direct calls to retrieve memories.\n\nYou have the following options to fetch generated memories:\n\n- [Get memory](#get-memory): Get the full content of a single memory.\n\n- [List memories](#list-memories): List memories\n\n- [Retrieve memories](#scope-based): Retrieve memories using scope-based memory retrieval. Retrieve memories using similarity search or all memories within the scope.\n\nBefore you begin\n----------------\n\nTo complete the steps demonstrated in this page, you must first follow the steps in [Set up for Memory Bank](/vertex-ai/generative-ai/docs/agent-engine/memory-bank/set-up).\n\nGet memory\n----------\n\nUse `GetMemories` to get the full content of a single memory: \n\n memory = client.agent_engines.get_memory(name=\"\u003cvar translate=\"no\"\u003eMEMORY_NAME\u003c/var\u003e\")\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eMEMORY_NAME\u003c/var\u003e: A fully-qualified memory name in the format \"projects/.../locations/.../reasoningEngines/.../memories...\".\n\nList memories\n-------------\n\nUse `ListMemories` to fetch all memories in your Memory Bank. \n\n pager = client.agent_engines.list_memories(name=agent_engine.api_resource.name)\n for page in pager:\n print(page)\n\nFetch memories using scope-based retrieval\n------------------------------------------\n\nYou can use `RetrieveMemories` to retrieve memories for a particular scope. Only memories that have the exact same scope (independent of order) as the retrieval request are returned. For example, you can retrieve all memories that are scoped to a particular user by using `{\"user_id\": \"123\"}`. If no memories are returned, Memory Bank doesn't have any memories for the provided scope.\n\nA memory's scope is defined when the memory is generated or created and is immutable.\n\nYou can use `RetrieveMemories` to perform the following operations for a particular scope:\n\n- [Retrieve memories using similarity search](#similarity-search)\n- [Retrieve all memories](#retrieve-all)\n\n### Retrieve memories using similarity search\n\nFor cases where you have many memories for a particular scope, you can use similarity search to retrieve only the most similar memories by providing similarity search parameters. Memory Bank only considers memories that have exactly the same scope as the request when performing similarity search. Similarity search compares the embedding vectors between memories' facts and the request's search query.\n\nReturned memories are sorted from most similar (shortest Euclidean distance) to least similar (greatest Euclidean distance): \n\n results = client.agent_engines.retrieve_memories(\n name=agent_engine.api_resource.name,\n scope=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSCOPE\u003c/span\u003e\u003c/var\u003e,\n similarity_search_params={\n \"search_query\": \"\u003cvar translate=\"no\"\u003eQUERY\u003c/var\u003e\",\n # Optional. Defaults to 3.\n \"top_k\": 3\n }\n )\n # RetrieveMemories returns a pager. You can use `list` to retrieve all memories.\n list(results)\n\n \"\"\"\n Returns:\n\n [\n RetrieveMemoriesResponseRetrievedMemory(\n memory=Memory(\n name=\"projects/.../locations/.../reasoningEngines/.../memories/...\",\n ...\n fact=\"This is a fact.\"\n },\n distance=0.5\n ),\n RetrieveMemoriesResponseRetrievedMemory(\n memory=Memory(\n name=\"projects/.../locations/.../reasoningEngines/.../memories/...\",\n ...\n fact=\"This is another fact.\"\n },\n distance=0.7\n ),\n ]\n \"\"\"\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eQUERY\u003c/var\u003e: The query for which to perform similarity search. For example, you can use the last user turn of the conversation as the query.\n\n- \u003cvar translate=\"no\"\u003eSCOPE\u003c/var\u003e: A dictionary, representing the scope for the similarity search. For example, `{\"user_id\": \"123\"}`. Only memories with the same scope as the request are considered.\n\n### Retrieve all memories\n\nIf no similarity search parameters are provided, `RetrieveMemories` returns all memories that have the provided scope, regardless of their similarity with the current conversation. \n\n results = client.agent_engines.retrieve_memories(\n name=agent_engine.api_resource.name,\n scope=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSCOPE\u003c/span\u003e\u003c/var\u003e\n )\n # RetrieveMemories returns a pager. You can use `list` to retrieve all pages' memories.\n list(results)\n\n \"\"\"\n Returns:\n\n [\n RetrieveMemoriesResponseRetrievedMemory(\n memory=Memory(\n name=\"projects/.../locations/.../reasoningEngines/.../memories/...\",\n ...\n fact=\"This is a fact.\"\n }\n ),\n RetrieveMemoriesResponseRetrievedMemory(\n memory=Memory(\n name=\"projects/.../locations/.../reasoningEngines/.../memories/...\",\n ...\n fact=\"This is another fact.\"\n }\n ),\n ]\n \"\"\"\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSCOPE\u003c/var\u003e: A dictionary representing the scope for retrieval. For example, `{\"user_id\": \"123\"}`. Only memories with the same scope as the request are returned."]]