{"id":27431044,"url":"https://github.com/ai-mindset/texttograph","last_synced_at":"2025-08-08T08:53:59.677Z","repository":{"id":284226149,"uuid":"936580843","full_name":"ai-mindset/TextToGraph","owner":"ai-mindset","description":"Transforms text files into interactive relationship graphs by extracting character relationships using LLMs","archived":false,"fork":false,"pushed_at":"2025-03-24T19:38:08.000Z","size":2590,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T15:52:54.838Z","etag":null,"topics":["graphs","langchain","llms","ollama","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ai-mindset.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-21T10:28:52.000Z","updated_at":"2025-03-24T19:38:11.000Z","dependencies_parsed_at":"2025-03-24T20:43:09.580Z","dependency_job_id":null,"html_url":"https://github.com/ai-mindset/TextToGraph","commit_stats":null,"previous_names":["ai-mindset/texttograph"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ai-mindset/TextToGraph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-mindset%2FTextToGraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-mindset%2FTextToGraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-mindset%2FTextToGraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-mindset%2FTextToGraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ai-mindset","download_url":"https://codeload.github.com/ai-mindset/TextToGraph/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai-mindset%2FTextToGraph/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269393607,"owners_count":24409755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphs","langchain","llms","ollama","sqlite"],"created_at":"2025-04-14T15:28:26.913Z","updated_at":"2025-08-08T08:53:59.650Z","avatar_url":"https://github.com/ai-mindset.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TextToGraph\n\nA Python-based system that transforms text files into interactive relationship graphs by extracting character relationships using LLMs, storing data in SQLite, and generating network visualisations.\n\n## Overview\n\nTextToGraph analyses text documents containing character information, extracts relationships between characters using Large Language Models (LLMs), and creates a knowledge graph database of characters and their relationships. It then visualises these relationships as an animated network graph.\n\n## Features\n\n- Text processing with chunk-based analysis\n- Character and relationship extraction using Ollama LLMs\n- Persistent storage using SQLite\n- Advanced network visualisation with:\n  - Colourblind-friendly design\n  - Interactive animation\n  - Optimised node layout\n  - Relationship strength indicators\n\n## Requirements\n\n- Python 3.10+\n- Ollama server running locally (with mistral-small and nomic-embed-text models)\n- Required Python packages:\n  - langchain\n  - langchain_ollama\n  - langchain_text_splitters\n  - matplotlib\n  - networkx\n  - numpy\n  - pydantic\n\n## Project Structure\n\n- `constants.py`: Configuration parameters for the application\n- `logger.py`: Logging utilities\n- `main.py`: Core functionality for processing texts and building the knowledge graph\n- `plot_graph.py`: Network visualisation tools\n- `__init__.py`: Package initialisation\n\n## Usage\n\n### 1. Set up the directory structure\n\n```\n├── data/           # Database storage\n├── plots/          # Generated visualisations\n├── text/           # Input text files (.txt or .md)\n└── texttograph/    # The code module\n```\n\n### 2. Prepare your text files\n\nPlace character description text files in the `text/` directory. Each file should contain information about a character and their relationships with other characters. The filename (without extension) will be used as the character ID.\n\n### 3. Start the Ollama server\n\nEnsure the Ollama server is running locally with the required models:\n\n```bash\nollama serve\n```\n\n### 4. Run the main processing script\n\n```bash\npython -m texttograph.main\n```\n\nThis will:\n- Read all text files from the `text/` directory\n- Process and chunk the content\n- Generate embeddings\n- Extract character relationships using LLMs\n- Store all data in the SQLite database\n\n### 5. Generate the visualisation\n\n```bash\npython -m texttograph.plot_graph\n```\n\nThis will create an animated network graph of character relationships and save it to the path specified in `constants.py` (default: `plots/character_graph.mp4`).\n\n## Configuration\n\nEdit `constants.py` to configure:\n\n- `CHUNK_SIZE`: Size of text chunks for processing (default: 1000)\n- `CHUNK_OVERLAP`: Overlap between chunks (default: 20% of chunk size)\n- `PLOT_DIRECTORY`: Where visualisations are saved (default: \"plots\")\n- `TEXT_DIRECTORY`: Where input text files are located (default: \"text\")\n- `DB_DIRECTORY`: Database storage location (default: \"data\")\n- `MODEL`: Ollama model to use (default: \"mistral-small:24b-instruct-2501-q4_K_M\")\n- `LOG_LEVEL`: Logging verbosity (default: \"INFO\")\n\n## How It Works\n\n1. **Text Processing**: \n   - Reads text files from the `text/` directory\n   - Splits content into overlapping chunks\n   - Generates embeddings for each chunk\n\n2. **Relationship Extraction**:\n   - Uses LLMs to identify characters, traits, and relationships in the text\n   - Parses the output into structured `Character` and `Relationship` objects\n\n3. **Database Storage**:\n   - Initialises an SQLite database with tables for documents, nodes, and edges\n   - Stores the original content, chunks, embeddings, characters, and relationships\n\n4. **Network Visualisation**:\n   - Creates a directed graph using NetworkX\n   - Assigns visually distinct attributes based on character grouping\n   - Generates an animation showing the network formation\n\n## Advanced Usage\n\n### Custom Database Path\n\n```bash\npython -m texttograph.main --db path/to/database.db\n```\n\n### Custom Text Directory\n\n```bash\npython -m texttograph.main --texts path/to/texts\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-mindset%2Ftexttograph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fai-mindset%2Ftexttograph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai-mindset%2Ftexttograph/lists"}