Skip to content
Draft
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
2 changes: 1 addition & 1 deletion examples/004/images/main/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion examples/005/images/main/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion examples/014/images/main/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 5 additions & 2 deletions examples/014/images/main/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ockam import Agent, Model, Node
from ockam import Agent, Model, Node, set_log_level


async def main(node):
Expand All @@ -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)
5 changes: 3 additions & 2 deletions implementations/python/examples/13.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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.
"""


async def main(node):
restaurants = SearchableKnowledge(
restaurants = Knowledge(
"restaurants",
searchable=True,
model=Model("ollama/nomic-embed-text"),
max_knowledge_size=4096,
)
Expand Down
5 changes: 3 additions & 2 deletions implementations/python/examples/14.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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.
"""


async def main(node):
ockam_documentation = SearchableKnowledge(
ockam_documentation = Knowledge(
"ockam_documentation",
searchable=True,
model=Model("ollama/nomic-embed-text"),
max_knowledge_size=4096,
)
Expand Down
2 changes: 1 addition & 1 deletion implementations/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions implementations/python/python/ockam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
TextPiece,
SearchHit,
SearchResults,
Knowledge,
UnsearchableKnowledge,
SearchableKnowledge,
InMemory,
Expand Down Expand Up @@ -85,6 +86,7 @@
# from .squads
"Squad",
# from .knowledge
"Knowledge",
"RemoteManager",
"Node",
"Tool",
Expand Down
2 changes: 2 additions & 0 deletions implementations/python/python/ockam/knowledge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .database import Database
from .extractors import TextExtractor
from .chunkers import Chunker, NaiveChunker
from .knowledge import Knowledge

__all__ = [
"Database",
Expand All @@ -19,6 +20,7 @@
"NoopKnowledge",
"Mem0Knowledge",
"SearchableKnowledge",
"Knowledge",
"SearchHit",
"SearchResults",
"SearchableKnowledge",
Expand Down
60 changes: 60 additions & 0 deletions implementations/python/python/ockam/knowledge/knowledge.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions implementations/python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading