diff --git a/examples/004/images/main/Dockerfile b/examples/004/images/main/Dockerfile index 86af5f89a2e..e11cff091df 100644 --- a/examples/004/images/main/Dockerfile +++ b/examples/004/images/main/Dockerfile @@ -1,3 +1,3 @@ -FROM ghcr.io/build-trust/ockam-python:latest +FROM ghcr.io/build-trust/ockam-python:37de4ebf9 COPY . . ENTRYPOINT ["python", "main.py"] diff --git a/examples/005/images/main/Dockerfile b/examples/005/images/main/Dockerfile index 86af5f89a2e..e11cff091df 100644 --- a/examples/005/images/main/Dockerfile +++ b/examples/005/images/main/Dockerfile @@ -1,3 +1,3 @@ -FROM ghcr.io/build-trust/ockam-python:latest +FROM ghcr.io/build-trust/ockam-python:37de4ebf9 COPY . . ENTRYPOINT ["python", "main.py"] diff --git a/examples/014/images/main/Dockerfile b/examples/014/images/main/Dockerfile index c0f723747cf..e11cff091df 100644 --- a/examples/014/images/main/Dockerfile +++ b/examples/014/images/main/Dockerfile @@ -1,3 +1,3 @@ -FROM ghcr.io/build-trust/ockam-python:b0f73e7d1 +FROM ghcr.io/build-trust/ockam-python:37de4ebf9 COPY . . ENTRYPOINT ["python", "main.py"] diff --git a/examples/014/images/main/main.py b/examples/014/images/main/main.py index f5a9de1526c..3b58aabc647 100644 --- a/examples/014/images/main/main.py +++ b/examples/014/images/main/main.py @@ -1,4 +1,4 @@ -from ockam import Agent, Model, Node +from ockam import Agent, Model, Node, set_log_level async def main(node): @@ -16,4 +16,7 @@ async def main(node): ) -Node.start(main, llm_debug=True) +set_log_level("mem0.memory.main", "INFO") +set_log_level("agent", "INFO") + +Node.start(main) diff --git a/implementations/python/examples/13.py b/implementations/python/examples/13.py index 80e44eb3c22..dddce767332 100644 --- a/implementations/python/examples/13.py +++ b/implementations/python/examples/13.py @@ -1,4 +1,4 @@ -from ockam import Agent, Model, Node, SearchableKnowledge +from ockam import Agent, Model, Node, Knowledge """ This example shows how a model can be enriched with knowledge coming from inlined documents. @@ -6,8 +6,9 @@ async def main(node): - restaurants = SearchableKnowledge( + restaurants = Knowledge( "restaurants", + searchable=True, model=Model("ollama/nomic-embed-text"), max_knowledge_size=4096, ) diff --git a/implementations/python/examples/14.py b/implementations/python/examples/14.py index 9d31bb0e33c..81e523a008e 100644 --- a/implementations/python/examples/14.py +++ b/implementations/python/examples/14.py @@ -1,4 +1,4 @@ -from ockam import Agent, Model, Node, SearchableKnowledge +from ockam import Agent, Model, Node, Knowledge """ This example shows how a model can be enriched with knowledge coming from documents retrieved online. @@ -6,8 +6,9 @@ async def main(node): - ockam_documentation = SearchableKnowledge( + ockam_documentation = Knowledge( "ockam_documentation", + searchable=True, model=Model("ollama/nomic-embed-text"), max_knowledge_size=4096, ) diff --git a/implementations/python/pyproject.toml b/implementations/python/pyproject.toml index 5e5502f600c..030491cda85 100644 --- a/implementations/python/pyproject.toml +++ b/implementations/python/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "docstring-parser>=0.16", "fastapi>=0.103.1", "litellm @ git+https://github.com/build-trust/litellm.git@ba33a4d4b165c276f7eb6a681fbe1ba23466be2f", - "mem0ai @ git+https://github.com/build-trust/mem0.git@bc7162e01520fcfb625cc1ee0ae998ed5a6a5ba3", + "mem0ai @ git+https://github.com/build-trust/mem0.git@8304988e3e74b18db45564eed5629c27db67ec63", "starlette>=0.27.0", "scipy>=1.15.2", "psycopg[binary]>=3.2.6", diff --git a/implementations/python/python/ockam/__init__.py b/implementations/python/python/ockam/__init__.py index 05d6e7c524a..6ca8c866fea 100644 --- a/implementations/python/python/ockam/__init__.py +++ b/implementations/python/python/ockam/__init__.py @@ -15,6 +15,7 @@ TextPiece, SearchHit, SearchResults, + Knowledge, UnsearchableKnowledge, SearchableKnowledge, InMemory, @@ -85,6 +86,7 @@ # from .squads "Squad", # from .knowledge + "Knowledge", "RemoteManager", "Node", "Tool", diff --git a/implementations/python/python/ockam/knowledge/__init__.py b/implementations/python/python/ockam/knowledge/__init__.py index c44539490a2..c59656e88fc 100644 --- a/implementations/python/python/ockam/knowledge/__init__.py +++ b/implementations/python/python/ockam/knowledge/__init__.py @@ -9,6 +9,7 @@ from .database import Database from .extractors import TextExtractor from .chunkers import Chunker, NaiveChunker +from .knowledge import Knowledge __all__ = [ "Database", @@ -19,6 +20,7 @@ "NoopKnowledge", "Mem0Knowledge", "SearchableKnowledge", + "Knowledge", "SearchHit", "SearchResults", "SearchableKnowledge", diff --git a/implementations/python/python/ockam/knowledge/knowledge.py b/implementations/python/python/ockam/knowledge/knowledge.py new file mode 100644 index 00000000000..4263a9a0ba4 --- /dev/null +++ b/implementations/python/python/ockam/knowledge/knowledge.py @@ -0,0 +1,60 @@ +from typing import Optional + + +from .protocol import KnowledgeProvider, Storage +from .searchable import SearchableKnowledge +from .unsearchable import UnsearchableKnowledge +from ..models.model import Model +from .chunkers.naive import NaiveChunker +from .chunkers import Chunker +from .extractors import TextExtractor +from .in_memory import InMemory + + +class Knowledge(KnowledgeProvider): + def __init__( + self, + name: str, + searchable=False, + # shared + storage: Storage = InMemory(), + text_extractor: TextExtractor = None, + max_knowledge_size: int = 4096, + # searchable-specific + model: Model = None, + chunker: Chunker = NaiveChunker(), + max_results: int = 10, + max_distance: float = 0.2, + # unsearchable-specific + document_name: Optional[str] = None, + ): + self.searchable = searchable + + if self.searchable: + self.knowledge = SearchableKnowledge( + name, + storage=storage, + text_extractor=text_extractor, + max_knowledge_size=max_knowledge_size, + model=model, + chunker=chunker, + max_results=max_results, + max_distance=max_distance, + ) + else: + self.knowledge = UnsearchableKnowledge( + name, + storage=storage, + text_extractor=text_extractor, + max_knowledge_size=max_knowledge_size, + document_name=document_name, + ) + + async def add_document(self, document_name: str, document_url: str, content_type: Optional[str] = None): + return await self.knowledge.add_document(document_name, document_url, content_type) + + async def add_text(self, document_name: str, text: str, content_type: Optional[str] = None): + return await self.knowledge.add_text(document_name, text, content_type) + + async def search_knowledge(self, scope: Optional[str], conversation: Optional[str], query: str) -> Optional[str]: + return await self.knowledge.search_knowledge(scope, conversation, query) diff --git a/implementations/python/python/ockam/knowledge/unsearchable.py b/implementations/python/python/ockam/knowledge/unsearchable.py index 0b3dc122700..fae77904d2c 100644 --- a/implementations/python/python/ockam/knowledge/unsearchable.py +++ b/implementations/python/python/ockam/knowledge/unsearchable.py @@ -58,7 +58,7 @@ async def add_document(self, document_name: str, document_url: str, content_type whole_document, ) - async def add_text(self, document_name: str, text: str): + async def add_text(self, document_name: str, text: str, content_type: Optional[str] = None): await self.storage.store_document( self.name, document_name, diff --git a/implementations/python/uv.lock b/implementations/python/uv.lock index 93c033c58a0..6120444550f 100644 --- a/implementations/python/uv.lock +++ b/implementations/python/uv.lock @@ -898,7 +898,7 @@ wheels = [ [[package]] name = "mem0ai" version = "0.1.111" -source = { git = "https://github.com/build-trust/mem0.git?rev=bc7162e01520fcfb625cc1ee0ae998ed5a6a5ba3#bc7162e01520fcfb625cc1ee0ae998ed5a6a5ba3" } +source = { git = "https://github.com/build-trust/mem0.git?rev=8304988e3e74b18db45564eed5629c27db67ec63#8304988e3e74b18db45564eed5629c27db67ec63" } dependencies = [ { name = "openai" }, { name = "posthog" }, @@ -1065,7 +1065,7 @@ requires-dist = [ { name = "fastapi", specifier = ">=0.103.1" }, { name = "filetype", specifier = ">=1.2.0" }, { name = "litellm", git = "https://github.com/build-trust/litellm.git?rev=ba33a4d4b165c276f7eb6a681fbe1ba23466be2f" }, - { name = "mem0ai", git = "https://github.com/build-trust/mem0.git?rev=bc7162e01520fcfb625cc1ee0ae998ed5a6a5ba3" }, + { name = "mem0ai", git = "https://github.com/build-trust/mem0.git?rev=8304988e3e74b18db45564eed5629c27db67ec63" }, { name = "psycopg", extras = ["binary"], specifier = ">=3.2.6" }, { name = "pylint" }, { name = "pypdfium2", specifier = ">=4.30" },