Skip to content

Commit 614da78

Browse files
committed
chore(python): Knowledge renaming
1 parent 327828e commit 614da78

File tree

12 files changed

+82
-13
lines changed

12 files changed

+82
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM ghcr.io/build-trust/ockam-python:latest
1+
FROM ghcr.io/build-trust/ockam-python:37de4ebf9
22
COPY . .
33
ENTRYPOINT ["python", "main.py"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM ghcr.io/build-trust/ockam-python:latest
1+
FROM ghcr.io/build-trust/ockam-python:37de4ebf9
22
COPY . .
33
ENTRYPOINT ["python", "main.py"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM ghcr.io/build-trust/ockam-python:b0f73e7d1
1+
FROM ghcr.io/build-trust/ockam-python:37de4ebf9
22
COPY . .
33
ENTRYPOINT ["python", "main.py"]

examples/014/images/main/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ockam import Agent, Model, Node
1+
from ockam import Agent, Model, Node, set_log_level
22

33

44
async def main(node):
@@ -16,4 +16,7 @@ async def main(node):
1616
)
1717

1818

19-
Node.start(main, llm_debug=True)
19+
set_log_level("mem0.memory.main", "INFO")
20+
set_log_level("agent", "INFO")
21+
22+
Node.start(main)

implementations/python/examples/13.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from ockam import Agent, Model, Node, SearchableKnowledge
1+
from ockam import Agent, Model, Node, Knowledge
22

33
"""
44
This example shows how a model can be enriched with knowledge coming from inlined documents.
55
"""
66

77

88
async def main(node):
9-
restaurants = SearchableKnowledge(
9+
restaurants = Knowledge(
1010
"restaurants",
11+
searchable=True,
1112
model=Model("ollama/nomic-embed-text"),
1213
max_knowledge_size=4096,
1314
)

implementations/python/examples/14.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from ockam import Agent, Model, Node, SearchableKnowledge
1+
from ockam import Agent, Model, Node, Knowledge
22

33
"""
44
This example shows how a model can be enriched with knowledge coming from documents retrieved online.
55
"""
66

77

88
async def main(node):
9-
ockam_documentation = SearchableKnowledge(
9+
ockam_documentation = Knowledge(
1010
"ockam_documentation",
11+
searchable=True,
1112
model=Model("ollama/nomic-embed-text"),
1213
max_knowledge_size=4096,
1314
)

implementations/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"docstring-parser>=0.16",
1717
"fastapi>=0.103.1",
1818
"litellm @ git+https://github.com/build-trust/litellm.git@ba33a4d4b165c276f7eb6a681fbe1ba23466be2f",
19-
"mem0ai @ git+https://github.com/build-trust/mem0.git@bc7162e01520fcfb625cc1ee0ae998ed5a6a5ba3",
19+
"mem0ai @ git+https://github.com/build-trust/mem0.git@8304988e3e74b18db45564eed5629c27db67ec63",
2020
"starlette>=0.27.0",
2121
"scipy>=1.15.2",
2222
"psycopg[binary]>=3.2.6",

implementations/python/python/ockam/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
TextPiece,
1616
SearchHit,
1717
SearchResults,
18+
Knowledge,
1819
UnsearchableKnowledge,
1920
SearchableKnowledge,
2021
InMemory,
@@ -85,6 +86,7 @@
8586
# from .squads
8687
"Squad",
8788
# from .knowledge
89+
"Knowledge",
8890
"RemoteManager",
8991
"Node",
9092
"Tool",

implementations/python/python/ockam/knowledge/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .database import Database
1010
from .extractors import TextExtractor
1111
from .chunkers import Chunker, NaiveChunker
12+
from .knowledge import Knowledge
1213

1314
__all__ = [
1415
"Database",
@@ -19,6 +20,7 @@
1920
"NoopKnowledge",
2021
"Mem0Knowledge",
2122
"SearchableKnowledge",
23+
"Knowledge",
2224
"SearchHit",
2325
"SearchResults",
2426
"SearchableKnowledge",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import Optional
2+
3+
4+
from .protocol import KnowledgeProvider, Storage
5+
from .searchable import SearchableKnowledge
6+
from .unsearchable import UnsearchableKnowledge
7+
from ..models.model import Model
8+
from .chunkers.naive import NaiveChunker
9+
from .chunkers import Chunker
10+
from .extractors import TextExtractor
11+
from .in_memory import InMemory
12+
13+
14+
class Knowledge(KnowledgeProvider):
15+
def __init__(
16+
self,
17+
name: str,
18+
searchable=False,
19+
# shared
20+
storage: Storage = InMemory(),
21+
text_extractor: TextExtractor = None,
22+
max_knowledge_size: int = 4096,
23+
# searchable-specific
24+
model: Model = None,
25+
chunker: Chunker = NaiveChunker(),
26+
max_results: int = 10,
27+
max_distance: float = 0.2,
28+
# unsearchable-specific
29+
document_name: Optional[str] = None,
30+
):
31+
self.searchable = searchable
32+
33+
if self.searchable:
34+
self.knowledge = SearchableKnowledge(
35+
name,
36+
storage=storage,
37+
text_extractor=text_extractor,
38+
max_knowledge_size=max_knowledge_size,
39+
model=model,
40+
chunker=chunker,
41+
max_results=max_results,
42+
max_distance=max_distance,
43+
)
44+
else:
45+
self.knowledge = UnsearchableKnowledge(
46+
name,
47+
storage=storage,
48+
text_extractor=text_extractor,
49+
max_knowledge_size=max_knowledge_size,
50+
document_name=document_name,
51+
)
52+
53+
async def add_document(self, document_name: str, document_url: str, content_type: Optional[str] = None):
54+
return await self.knowledge.add_document(document_name, document_url, content_type)
55+
56+
async def add_text(self, document_name: str, text: str, content_type: Optional[str] = None):
57+
return await self.knowledge.add_text(document_name, text, content_type)
58+
59+
async def search_knowledge(self, scope: Optional[str], conversation: Optional[str], query: str) -> Optional[str]:
60+
return await self.knowledge.search_knowledge(scope, conversation, query)

0 commit comments

Comments
 (0)