import-kb 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nebiyu Samuel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: import-kb
3
+ Version: 0.1.0
4
+ Summary: A package for importing knowledge and embedding text.
5
+ Author-email: Coderskin <your.email@example.com>
6
+ License: MIT
7
+ Keywords: knowledge,embedding,openai,chromadb
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: openai>=0.27.0
15
+ Requires-Dist: chromadb>=0.3.21
16
+ Requires-Dist: python-dotenv>=0.20.0
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=6.2.5; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # import-knowledge-package/import-knowledge-package/README.md
22
+
23
+ # Import Knowledge Package
24
+
25
+ This project provides a Python package for importing and processing knowledge from specified JSONL and curriculum files. It utilizes OpenAI's embedding model to generate embeddings for the knowledge data, which can then be stored in a Chroma database for later retrieval and use.
26
+
27
+ ## Project Structure
28
+
29
+ ```
30
+ import-knowledge-package
31
+ ├── KB
32
+ │ ├── curriculum.metta
33
+ │ ├── max_distilled_knowledge.jsonl
34
+ │ └── oma_distilled_knowledge.jsonl
35
+ ├── src
36
+ │ └── import_knowledge
37
+ │ ├── __init__.py
38
+ │ └── import_knowledge.py
39
+ ├── pyproject.toml
40
+ ├── setup.py
41
+ ├── MANIFEST.in
42
+ └── README.md
43
+ ```
44
+
45
+ ### KB Directory
46
+
47
+ - **curriculum.metta**: Contains the curriculum data used for knowledge transfer.
48
+ - **max_distilled_knowledge.jsonl**: Contains distilled knowledge data related to "max".
49
+ - **oma_distilled_knowledge.jsonl**: Contains distilled knowledge data related to "oma".
50
+
51
+ ### Source Directory
52
+
53
+ - **import_knowledge/__init__.py**: Marks the directory as a Python package.
54
+ - **import_knowledge.py**: Contains the main logic for importing knowledge, including functions for embedding text and processing knowledge files.
55
+
56
+ ## Installation
57
+
58
+ To install the package, clone the repository and run:
59
+
60
+ ```bash
61
+ pip install .
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ After installation, you can use the package to import knowledge by running the `import_knowledge.py` script. Ensure that your environment is set up with the necessary API keys and dependencies.
67
+
68
+ ## Dependencies
69
+
70
+ - OpenAI API
71
+ - ChromaDB
72
+ - dotenv
73
+
74
+ Make sure to install the required dependencies listed in `setup.py` or `pyproject.toml`.
75
+
76
+ ## License
77
+
78
+ This project is licensed under the MIT License. See the LICENSE file for more details.
@@ -0,0 +1,58 @@
1
+ # import-knowledge-package/import-knowledge-package/README.md
2
+
3
+ # Import Knowledge Package
4
+
5
+ This project provides a Python package for importing and processing knowledge from specified JSONL and curriculum files. It utilizes OpenAI's embedding model to generate embeddings for the knowledge data, which can then be stored in a Chroma database for later retrieval and use.
6
+
7
+ ## Project Structure
8
+
9
+ ```
10
+ import-knowledge-package
11
+ ├── KB
12
+ │ ├── curriculum.metta
13
+ │ ├── max_distilled_knowledge.jsonl
14
+ │ └── oma_distilled_knowledge.jsonl
15
+ ├── src
16
+ │ └── import_knowledge
17
+ │ ├── __init__.py
18
+ │ └── import_knowledge.py
19
+ ├── pyproject.toml
20
+ ├── setup.py
21
+ ├── MANIFEST.in
22
+ └── README.md
23
+ ```
24
+
25
+ ### KB Directory
26
+
27
+ - **curriculum.metta**: Contains the curriculum data used for knowledge transfer.
28
+ - **max_distilled_knowledge.jsonl**: Contains distilled knowledge data related to "max".
29
+ - **oma_distilled_knowledge.jsonl**: Contains distilled knowledge data related to "oma".
30
+
31
+ ### Source Directory
32
+
33
+ - **import_knowledge/__init__.py**: Marks the directory as a Python package.
34
+ - **import_knowledge.py**: Contains the main logic for importing knowledge, including functions for embedding text and processing knowledge files.
35
+
36
+ ## Installation
37
+
38
+ To install the package, clone the repository and run:
39
+
40
+ ```bash
41
+ pip install .
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ After installation, you can use the package to import knowledge by running the `import_knowledge.py` script. Ensure that your environment is set up with the necessary API keys and dependencies.
47
+
48
+ ## Dependencies
49
+
50
+ - OpenAI API
51
+ - ChromaDB
52
+ - dotenv
53
+
54
+ Make sure to install the required dependencies listed in `setup.py` or `pyproject.toml`.
55
+
56
+ ## License
57
+
58
+ This project is licensed under the MIT License. See the LICENSE file for more details.
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "import-kb"
7
+ version = "0.1.0"
8
+ description = "A package for importing knowledge and embedding text."
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Coderskin", email = "your.email@example.com" }
12
+ ]
13
+ license = { text = "MIT" }
14
+ keywords = ["knowledge", "embedding", "openai", "chromadb"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+ requires-python = ">=3.7"
21
+ dependencies = [
22
+ "openai>=0.27.0",
23
+ "chromadb>=0.3.21",
24
+ "python-dotenv>=0.20.0",
25
+ ]
26
+
27
+ [project.optional-dependencies]
28
+ dev = [
29
+ "pytest>=6.2.5",
30
+ ]
31
+
32
+ [tool.setuptools]
33
+ package-dir = {"" = "src"}
34
+
35
+ [tool.setuptools.packages.find]
36
+ where = ["src"]
37
+
38
+ [tool.setuptools.package-data]
39
+ import_knowledge = ["KB/*.jsonl", "KB/*.metta"]
40
+
41
+ [project.scripts]
42
+ import-knowledge = "import_knowledge.import_knowledge:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: import-kb
3
+ Version: 0.1.0
4
+ Summary: A package for importing knowledge and embedding text.
5
+ Author-email: Coderskin <your.email@example.com>
6
+ License: MIT
7
+ Keywords: knowledge,embedding,openai,chromadb
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: openai>=0.27.0
15
+ Requires-Dist: chromadb>=0.3.21
16
+ Requires-Dist: python-dotenv>=0.20.0
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=6.2.5; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # import-knowledge-package/import-knowledge-package/README.md
22
+
23
+ # Import Knowledge Package
24
+
25
+ This project provides a Python package for importing and processing knowledge from specified JSONL and curriculum files. It utilizes OpenAI's embedding model to generate embeddings for the knowledge data, which can then be stored in a Chroma database for later retrieval and use.
26
+
27
+ ## Project Structure
28
+
29
+ ```
30
+ import-knowledge-package
31
+ ├── KB
32
+ │ ├── curriculum.metta
33
+ │ ├── max_distilled_knowledge.jsonl
34
+ │ └── oma_distilled_knowledge.jsonl
35
+ ├── src
36
+ │ └── import_knowledge
37
+ │ ├── __init__.py
38
+ │ └── import_knowledge.py
39
+ ├── pyproject.toml
40
+ ├── setup.py
41
+ ├── MANIFEST.in
42
+ └── README.md
43
+ ```
44
+
45
+ ### KB Directory
46
+
47
+ - **curriculum.metta**: Contains the curriculum data used for knowledge transfer.
48
+ - **max_distilled_knowledge.jsonl**: Contains distilled knowledge data related to "max".
49
+ - **oma_distilled_knowledge.jsonl**: Contains distilled knowledge data related to "oma".
50
+
51
+ ### Source Directory
52
+
53
+ - **import_knowledge/__init__.py**: Marks the directory as a Python package.
54
+ - **import_knowledge.py**: Contains the main logic for importing knowledge, including functions for embedding text and processing knowledge files.
55
+
56
+ ## Installation
57
+
58
+ To install the package, clone the repository and run:
59
+
60
+ ```bash
61
+ pip install .
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ After installation, you can use the package to import knowledge by running the `import_knowledge.py` script. Ensure that your environment is set up with the necessary API keys and dependencies.
67
+
68
+ ## Dependencies
69
+
70
+ - OpenAI API
71
+ - ChromaDB
72
+ - dotenv
73
+
74
+ Make sure to install the required dependencies listed in `setup.py` or `pyproject.toml`.
75
+
76
+ ## License
77
+
78
+ This project is licensed under the MIT License. See the LICENSE file for more details.
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/import_kb.egg-info/PKG-INFO
5
+ src/import_kb.egg-info/SOURCES.txt
6
+ src/import_kb.egg-info/dependency_links.txt
7
+ src/import_kb.egg-info/entry_points.txt
8
+ src/import_kb.egg-info/requires.txt
9
+ src/import_kb.egg-info/top_level.txt
10
+ src/import_knowledge/__init__.py
11
+ src/import_knowledge/import_knowledge.py
12
+ src/import_knowledge/KB/curriculum.metta
13
+ src/import_knowledge/KB/max_distilled_knowledge.jsonl
14
+ src/import_knowledge/KB/oma_distilled_knowledge.jsonl
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ import-knowledge = import_knowledge.import_knowledge:main
@@ -0,0 +1,6 @@
1
+ openai>=0.27.0
2
+ chromadb>=0.3.21
3
+ python-dotenv>=0.20.0
4
+
5
+ [dev]
6
+ pytest>=6.2.5
@@ -0,0 +1 @@
1
+ import_knowledge
@@ -0,0 +1,2 @@
1
+ # FILE: /import-knowledge-package/import-knowledge-package/KB/curriculum.metta
2
+ # This file is intentionally left blank.
@@ -0,0 +1,27 @@
1
+ {
2
+ "id": "max_knowledge_001",
3
+ "document": "Max is known for his exceptional problem-solving skills and creativity. He often approaches challenges with a unique perspective, leading to innovative solutions.",
4
+ "metadata": {
5
+ "domain": "personal_development",
6
+ "type": "fact",
7
+ "tags": ["creativity", "problem-solving", "innovation"]
8
+ }
9
+ }
10
+ {
11
+ "id": "max_knowledge_002",
12
+ "document": "Max has a strong background in software development, particularly in Python and JavaScript. He has contributed to several open-source projects.",
13
+ "metadata": {
14
+ "domain": "technical_skills",
15
+ "type": "fact",
16
+ "tags": ["software development", "open-source", "Python", "JavaScript"]
17
+ }
18
+ }
19
+ {
20
+ "id": "max_knowledge_003",
21
+ "document": "Max enjoys collaborating with others and often takes on leadership roles in team projects. His communication skills are highly regarded.",
22
+ "metadata": {
23
+ "domain": "teamwork",
24
+ "type": "fact",
25
+ "tags": ["leadership", "communication", "collaboration"]
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "id": "oma_001",
3
+ "document": "Oma is a term used to refer to a grandmother in various cultures, often associated with wisdom and nurturing.",
4
+ "metadata": {
5
+ "domain": "family",
6
+ "type": "fact",
7
+ "tags": ["family", "grandmother", "wisdom"]
8
+ }
9
+ }
10
+ {
11
+ "id": "oma_002",
12
+ "document": "In many cultures, oma is a central figure in family gatherings, often sharing stories and traditions.",
13
+ "metadata": {
14
+ "domain": "family",
15
+ "type": "fact",
16
+ "tags": ["family", "tradition", "storytelling"]
17
+ }
18
+ }
19
+ {
20
+ "id": "oma_003",
21
+ "document": "The role of an oma can vary significantly between cultures, influencing family dynamics and values.",
22
+ "metadata": {
23
+ "domain": "cultural studies",
24
+ "type": "fact",
25
+ "tags": ["culture", "family dynamics", "values"]
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ # filepath: /import-knowledge-package/import-knowledge-package/src/import_knowledge/__init__.py
2
+ """This package provides functionality for importing knowledge from various sources."""
@@ -0,0 +1,152 @@
1
+ import os
2
+ import json
3
+ from pathlib import Path
4
+ import chromadb
5
+ import openai
6
+ from dotenv import load_dotenv
7
+
8
+ # Load API Key from .env
9
+ load_dotenv()
10
+
11
+ # Look for the DB path
12
+ _PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__))
13
+
14
+ # --- Configuration ---
15
+ EMBEDDING_MODEL = "text-embedding-3-large"
16
+ COLLECTION_NAME = "memories"
17
+ KNOWLEDGE_FILES = [
18
+ os.path.join(_PACKAGE_DIR, "KB", "oma_distilled_knowledge.jsonl"),
19
+ os.path.join(_PACKAGE_DIR, "KB", "max_distilled_knowledge.jsonl")
20
+ ]
21
+ CURRICULUM_FILE = os.path.join(_PACKAGE_DIR, "KB", "curriculum.metta")
22
+
23
+ DB_PATH = os.environ.get(
24
+ "CHROMA_DB_PATH",
25
+ "/PeTTa/chroma_db" if os.path.isdir("/PeTTa/chroma_db") else
26
+ os.path.join(_PACKAGE_DIR, "..", "..", "chroma_db")
27
+ )
28
+
29
+ # --- Embedding Function ---
30
+ def _embed_batch(texts):
31
+ """Embed a list of texts via OpenAI. Returns list of float vectors."""
32
+ client = openai.OpenAI()
33
+ resp = client.embeddings.create(model=EMBEDDING_MODEL, input=texts)
34
+ return [item.embedding for item in resp.data]
35
+
36
+ def main():
37
+ has_any_knowledge = any(Path(f).exists() for f in KNOWLEDGE_FILES)
38
+ if not has_any_knowledge and not Path(CURRICULUM_FILE).exists():
39
+ print("Error: Neither knowledge nor curriculum files were found.")
40
+ return
41
+
42
+ print(f"Connecting to Agent LTM at: {DB_PATH}")
43
+ os.makedirs(DB_PATH, exist_ok=True)
44
+ client = chromadb.PersistentClient(path=DB_PATH)
45
+
46
+ collection = client.get_or_create_collection(
47
+ name=COLLECTION_NAME,
48
+ embedding_function=None,
49
+ )
50
+
51
+ ids = []
52
+ documents = []
53
+ metadatas = []
54
+ seen_ids = set()
55
+
56
+ for k_file in KNOWLEDGE_FILES:
57
+ if Path(k_file).exists():
58
+ print(f"Loading distilled knowledge from {k_file}...")
59
+ with open(k_file, "r", encoding="utf-8") as f:
60
+ for line in f:
61
+ if not line.strip():
62
+ continue
63
+
64
+ record = json.loads(line)
65
+ record_id = record["id"]
66
+
67
+ if record_id in seen_ids:
68
+ continue
69
+
70
+ seen_ids.add(record_id)
71
+ ids.append(record_id)
72
+ documents.append(record["document"])
73
+
74
+
75
+ meta = record.get("metadata", {})
76
+ clean_meta = {
77
+ "source": "distilled_memory",
78
+ "breadcrumb": f"LTM > {meta.get('domain', 'general')} > {meta.get('type', 'fact')}",
79
+ "type": "chunk",
80
+ "time": "knowledge_prior"
81
+ }
82
+
83
+ for k, v in meta.items():
84
+ if isinstance(v, list):
85
+ clean_meta[k] = " | ".join(v) if v else "None"
86
+ else:
87
+ clean_meta[k] = v
88
+
89
+ metadatas.append(clean_meta)
90
+ else:
91
+ print(f"Warning: {k_file} not found. Skipping...")
92
+
93
+ if Path(CURRICULUM_FILE).exists():
94
+ print("Loading curriculum...")
95
+ with open(CURRICULUM_FILE, "r", encoding="utf-8") as f:
96
+ content = f.read()
97
+ chunks = [chunk.strip() for chunk in content.split("\n\n") if chunk.strip()]
98
+
99
+ for idx, chunk in enumerate(chunks):
100
+ curriculum_id = f"curriculum_mem_{idx}"
101
+
102
+ if curriculum_id in seen_ids:
103
+ continue
104
+
105
+ seen_ids.add(curriculum_id)
106
+ ids.append(curriculum_id)
107
+ documents.append(chunk)
108
+ metadatas.append({
109
+ "source": "curriculum",
110
+ "breadcrumb": "LTM > curriculum",
111
+ "type": "chunk",
112
+ "time": "knowledge_prior"
113
+ })
114
+ else:
115
+ print(f"Warning: {CURRICULUM_FILE} not found. Skipping...")
116
+
117
+
118
+
119
+ count = len(ids)
120
+ if count == 0:
121
+ print("No documents to process.")
122
+ return
123
+
124
+ print(f"Generating OpenAI '{EMBEDDING_MODEL}' embeddings for {count} records. Please wait...")
125
+
126
+ batch_size = 100
127
+ for i in range(0, count, batch_size):
128
+ end = min(i + batch_size, count)
129
+
130
+ batch_docs = documents[i:end]
131
+
132
+ # Manually compute the embeddings via OpenAI API to match the agent's expected vector lengths
133
+ try:
134
+ batch_embeddings = _embed_batch(batch_docs)
135
+ except Exception as e:
136
+ print(f"Fatal error generating embeddings: {e}")
137
+ return
138
+
139
+ # Use upside instead of add to gracefully handle re-runs
140
+ collection.upsert(
141
+ ids=ids[i:end],
142
+ embeddings=batch_embeddings,
143
+ documents=batch_docs,
144
+ metadatas=metadatas[i:end]
145
+ )
146
+ print(f" -> Embedded and upserted batch {i} to {end}")
147
+
148
+ print("\nKnowledge Transfer Complete!")
149
+ print(f"New Agent Database now has {collection.count()} total memories.")
150
+
151
+ if __name__ == "__main__":
152
+ main()