開始使用代理程式記憶體
本文將引導您完成安裝「代理程式記憶體」及執行基本記憶體作業,包括儲存及擷取使用者相關資訊環境。
必備條件
確保您符合以下條件:
- 存取 Oracle AI Database (請參閱在本機執行 Oracle AI Database)
- Python 3。10 或更新版本
安裝 SDK
若要安裝「代理程式記憶體」,請執行:
pip install "oracleagentmemory==26.4.0"
使用 pip 進行安裝時,會在支援的平台上提取預先建立的二進位操控盤。
起始記憶體執行處理
設定內嵌程式、LLM 以及資料庫連線,以建立 OracleAgentMemory 執行處理。
from oracleagentmemory.core.oracleagentmemory import OracleAgentMemory
from oracleagentmemory.apis.searchscope import SearchScope
from oracleagentmemory.core.embedders.embedder import Embedder
from oracleagentmemory.core.llms.llm import Llm
embedder = Embedder(model="YOUR_EMBEDDING_MODEL")
llm = Llm(model="YOUR_LLM")
db_pool = ... #an oracledb connection or connection pool
memory = OracleAgentMemory(connection=db_pool, embedder=embedder, llm=llm)
儲存記憶體項目
首先,請先建立執行緒、新增訊息以及儲存使用者的記憶體項目。
messages = [
{
"role": "user",
"content": (
"Orange juice has become my favorite breakfast drink lately, "
"what can I pair it with?"
),
},
{
"role": "assistant",
"content": (
"Nice! Orange juice goes great with something savory. "
"Try eggs and toast, avocado toast, or a breakfast sandwich."
),
},
]
thread = memory.create_thread(user_id="user_123")
#add_messages will add messages to the DB and extract memories automatically
thread.add_messages(messages)
#add_memory adds memory to the DB
thread.add_memory("The user likes orange juice with breakfast.")
擷取記憶體項目
使用使用者範圍的查詢搜尋記憶體。
results = memory.search(query="orange juice", scope=SearchScope(user_id="user_123"))
for result in results:
print(f"- [{result.record.record_type}] {result.content}")
輸出:
-[memory] The user likes orange juice with breakfast.
-[message] Orange juice has become my favorite breakfast drink lately, what can I pair it with?
-[message] Nice! Orange juice goes great with something savory.
Try eggs and toast,avocado toast, or a breakfast sandwich.
注意:顯示的輸出為圖解式。未來版本可能會傳回其他結果類型、欄位或排序。
模型相容性
自 2026 年 4 月起,下列大型語言模型 (LLM) 與內嵌模型與 oracleagentmemory 相容。
LLM
下列大型語言模型 (LLM) 已確認相容。
公升
openai/google/gemma-4-26B-A4B-itopenai/openai/gpt-oss-120b
OCI
oci/google.gemini-2.5-flashoci/google.gemini-2.5-flash-liteoci/google.gemini-2.5-prooci/xai.grok-3oci/xai.grok-3-fastoci/xai.grok-3-minioci/xai.grok-3-mini-fastoci/xai.grok-4oci/xai.grok-4-1-fast-non-reasoningoci/xai.grok-4-1-fast-reasoningoci/xai.grok-4-fast-non-reasoningoci/xai.grok-4-fast-reasoningoci/xai.grok-4.20-non-reasoningoci/xai.grok-4.20-reasoningoci/xai.grok-code-fast-1oci/cohere.command-latestoci/cohere.command-a-03-2025oci/cohere.command-a-reasoning-08-2025oci/cohere.command-a-vision-07-2025oci/cohere.command-a-translate-08-2025oci/cohere.command-plus-latestoci/cohere.cohere.command-r-08-2024oci/cohere.command-r-plus-08-2024
gemini
gemini/gemini-3.1-flash-lite-previewgemini/gemini-3-flash-previewgemini/gemini-3.1-pro-preview
人造的
anthropic/claude-opus-4-7anthropic/claude-opus-4-6anthropic/claude-sonnet-4-6anthropic/claude-haiku-4-5
openai
openai/gpt-4.1openai/gpt-4.1-miniopenai/gpt-4oopenai/gpt-5openai/gpt-5-miniopenai/gpt-5.1openai/gpt-5.2openai/gpt-5.4openai/gpt-5.4-mini
嵌入
已確認下列內嵌模型相容。
繁體中文
hosted_vllm/Snowflake/snowflake-arctic-embed-l-v2.0
OCI
oci/cohere.embed-english-v3.0oci/cohere.embed-english-light-v3.0oci/cohere.embed-multilingual-v3.0oci/cohere.embed-v4.0
gemini
gemini/gemini-embedding-001gemini/gemini-embedding-2-preview
openai
openai/text-embedding-3-largeopenai/text-embedding-3-small