Metadata-Version: 2.4
Name: everalgo-knowledge
Version: 0.1.1
Summary: EverAlgo knowledge: file-based knowledge extractors producing KnowledgeMemory.
Project-URL: Homepage, https://github.com/EverMind-AI/EverAlgo
Project-URL: Repository, https://github.com/EverMind-AI/EverAlgo
Project-URL: Issues, https://github.com/EverMind-AI/EverAlgo/issues
Project-URL: Documentation, https://github.com/EverMind-AI/EverAlgo/tree/main/packages/everalgo-knowledge
Project-URL: Changelog, https://github.com/EverMind-AI/EverAlgo/blob/main/packages/everalgo-knowledge/CHANGELOG.md
Author-email: EverMind <Evermind@shanda.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: everalgo,knowledge-extraction,llm,memory
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Requires-Dist: asgiref>=3.0
Requires-Dist: everalgo-core<2.0.0,>=0.3.0
Requires-Dist: everalgo-parser<2.0.0,>=0.2.0
Requires-Dist: tiktoken>=0.7
Description-Content-Type: text/markdown

# everalgo-knowledge

Extracts a flattened topic tree (`list[KnowledgeMemory]`) from parsed content (`ParsedContent`) via LLM.

## Use

```python
from everalgo.knowledge import KnowledgeExtractor
from everalgo.types import ParsedContent

parsed = ParsedContent(text="...", mime="text/markdown")
memories = await KnowledgeExtractor(llm=client).aextract(parsed, doc_id="doc1", title="My doc")
# memories[0] = synthetic doc root; rest = DFS-ordered topic nodes.
```

`llm`: any `everalgo.llm.LLMClient` (OpenAI-compatible), passed at construction. Sync bridge: `extract(...)`.

## Pipeline at a glance

```
ParsedContent
  → preprocess + atomize           (_block_split)
  → topic-tree LLM (per batch)     (TOPIC_TREE_EXTRACT_PROMPT_EN)
  → cross-batch merge (>1 batch)   (CONTENT_MERGE + TOPIC_MERGE)
  → postprocess: split unsplit leaves + assign uncovered blocks
  → tree assembly + DFS flatten    → list[KnowledgeMemory]
```

## Install

```bash
# This package is NOT published to PyPI (Private :: Do Not Upload classifier).
# Install within the workspace only:
uv sync --package everalgo-knowledge
```

## Live-LLM scripts

Run from the **repository root**. Put `LLM_API_KEY`, `LLM_BASE_URL`, `LLM_MODEL` in a `.env` file there first; each command block below sources it inline and is paste-and-run.

Smoke test — 2 fixtures, structural assertions only, no artifacts written:

```bash
set -a; source .env; set +a
uv run pytest -m integration packages/everalgo-knowledge/tests/functional/test_extraction_smoke.py
```

Run one doc — dumps result (JSON + optional HTML viz) under `tests/functional/outputs/`:

```bash
set -a; source .env; set +a
uv run python packages/everalgo-knowledge/examples/run_one_doc.py \
  packages/everalgo-knowledge/tests/functional/fixtures/idx_multi_topic.json --html
```

## Related distributions

- [`everalgo-parser`](../everalgo-parser/) — produces `ParsedContent` from raw files (fully implemented except video, which is deferred pending ADR)
- [`everalgo-core`](../everalgo-core/) — `KnowledgeMemory` type is defined here
