Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions aworld/core/context/amni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from .prompt.prompts import AMNI_CONTEXT_PROMPT
from .retrieval.artifacts import SearchArtifact
from .retrieval.artifacts.file import DirArtifact
from .retrieval.chunker import Chunk
from .retrieval.embeddings import EmbeddingsMetadata, SearchResults
from .state import ApplicationTaskContextState, ApplicationAgentState, TaskOutput, TaskWorkingState
from .state.agent_state import AgentWorkingState
Expand Down Expand Up @@ -255,7 +254,8 @@ async def get_knowledge_by_id(self, knowledge_id: str, namespace: str = "default
pass

@abc.abstractmethod
async def get_knowledge_chunk(self, knowledge_id: str, chunk_index: int) -> Optional[Chunk]:
async def get_knowledge_chunk(self, knowledge_id: str, chunk_index: int) -> Optional[Any]:
"""Deprecated: chunk-based retrieval is no longer supported."""
pass

# @abc.abstractmethod
Expand Down Expand Up @@ -1334,13 +1334,7 @@ async def offload_by_workspace(self, artifacts: list[Artifact], namespace="defau
"""
return await self.knowledge_service.offload_by_workspace(artifacts, namespace, biz_id)

def need_index(self, artifact: Artifact):
"""
Check if artifact needs indexing.

Delegates to KnowledgeService._need_index().
"""
return self.knowledge_service._need_index(artifact)
# NOTE: need_index is deprecated since retrieval indexing has been removed.


async def load_context_by_workspace(
Expand Down Expand Up @@ -1592,11 +1586,12 @@ async def get_knowledge_by_id(self, knowledge_id: str, namespace: str = "default
"""
return await self.knowledge_service.get_knowledge_by_id(knowledge_id, namespace)

async def get_knowledge_chunk(self, knowledge_id: str, chunk_index: int) -> Optional[Chunk]:
async def get_knowledge_chunk(self, knowledge_id: str, chunk_index: int) -> Optional[Any]:
"""
Get a specific chunk from a knowledge artifact.
Deprecated: Get a specific chunk from a knowledge artifact.

Delegates to KnowledgeService.get_knowledge_chunk().
Chunk-based retrieval has been disabled; this method is kept for
backward compatibility and will always return None.
"""
return await self.knowledge_service.get_knowledge_chunk(knowledge_id, chunk_index)

Expand Down
33 changes: 24 additions & 9 deletions aworld/core/context/amni/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

from aworld.config import ModelConfig
from aworld.config.conf import AgentMemoryConfig, SummaryPromptConfig, HistoryWriteStrategy
from aworld.core.memory import MemoryConfig
from aworld.core.memory import MemoryConfig, MemoryStore
from aworld.memory.db.sqlite import SQLiteMemoryStore
# from aworld.memory.db import SQLiteMemoryStore # Temporarily commented out to avoid import errors
from aworld.memory.main import MemoryFactory
from .retrieval.base import RetrieverFactory
from aworld.memory.main import MemoryFactory, InMemoryMemoryStore
from ...event.base import TopicType


Expand Down Expand Up @@ -228,19 +226,36 @@ def get_agent_memory_config(self, namespace: str = "default") -> AgentMemoryConf
return agent_context_config.to_memory_config()
return DEFAULT_AGENT_CONFIG.to_memory_config()

def _create_memory_store() -> MemoryStore:
"""
Create memory store backend instance.

Backend selection strategy:
- If MEMORY_BACKEND=sqlite, use SQLiteMemoryStore with DB_PATH (default: ./data/amni_context.db).
- Otherwise, default to InMemoryMemoryStore for lightweight, ephemeral usage.
"""
backend = os.getenv("MEMORY_BACKEND", "inmemory").lower()
if backend == "sqlite":
db_path = os.getenv("DB_PATH", "./data/amni_context.db")
return SQLiteMemoryStore(db_path=db_path)
return InMemoryMemoryStore()


def init_middlewares(init_memory: bool = True, init_retriever: bool = True) -> None:
"""
Initialize Amni middlewares.

Args:
init_memory: Whether to initialize memory subsystem.
init_retriever: Deprecated, kept for compatibility; RAG / retriever is no longer initialized here.
"""
# 1. Initialize memory
if init_memory:
MemoryFactory.init(
custom_memory_store=SQLiteMemoryStore(db_path=os.getenv("DB_PATH", "./data/amni_context.db")),
custom_memory_store=_create_memory_store(),
config=build_memory_config()
)

# 2. Initialize retriever
if init_retriever:
RetrieverFactory.init()

def build_memory_config():
return MemoryConfig(
provider="aworld",
Expand Down
Loading