{"id":17526834,"url":"https://github.com/parthsarthi03/raptor","last_synced_at":"2025-03-06T06:30:55.034Z","repository":{"id":224647282,"uuid":"763825934","full_name":"parthsarthi03/raptor","owner":"parthsarthi03","description":"The official implementation of RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval","archived":false,"fork":false,"pushed_at":"2024-03-21T14:16:41.000Z","size":875,"stargazers_count":266,"open_issues_count":9,"forks_count":29,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-03-21T15:35:09.928Z","etag":null,"topics":["agents","clustering","framework","language-model","llm","machine-learning","rag","retrieval","retrieval-augmented-generation","vector-database"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2401.18059","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parthsarthi03.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2024-02-27T01:33:26.000Z","updated_at":"2024-03-21T13:47:08.000Z","dependencies_parsed_at":"2024-03-21T15:44:33.125Z","dependency_job_id":null,"html_url":"https://github.com/parthsarthi03/raptor","commit_stats":null,"previous_names":["parthsarthi03/raptor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthsarthi03%2Fraptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthsarthi03%2Fraptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthsarthi03%2Fraptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parthsarthi03%2Fraptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parthsarthi03","download_url":"https://codeload.github.com/parthsarthi03/raptor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242161422,"owners_count":20081867,"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","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":["agents","clustering","framework","language-model","llm","machine-learning","rag","retrieval","retrieval-augmented-generation","vector-database"],"created_at":"2024-10-20T15:02:33.387Z","updated_at":"2025-03-06T06:30:54.594Z","avatar_url":"https://github.com/parthsarthi03.png","language":"Python","funding_links":[],"categories":["Python","2024.01","A01_文本生成_文本对话","*Ops for AI","🔬 Innovative Approaches","Image Generation \u0026 Editing"],"sub_categories":["RAPTOR【分层归纳】","大语言对话模型及数据","Model Serving \u0026 Inference","[Chat-with-your-Docs](https://github.com/mayooear/ai-pdf-chatbot-langchain)"],"readme":"\u003c!-- \u003cp align=\"center\"\u003e\n  \u003cimg align=\"center\" src=\"raptor.jpg\" width=\"1000px\" /\u003e\n\u003c/p\u003e\n\u003cp align=\"left\"\u003e --\u003e\n\n\u003c!-- \u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"raptor.jpg\" width=\"1000px\"\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"raptor_dark.png\" width=\"1000px\"\u003e\n  \n\u003c/picture\u003e --\u003e\n\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"raptor_dark.png\"\u003e\n  \u003cimg alt=\"Shows an illustrated sun in light color mode and a moon with stars in dark color mode.\" src=\"raptor.jpg\"\u003e\n\u003c/picture\u003e\n\n## RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval\n\n**RAPTOR** introduces a novel approach to retrieval-augmented language models by constructing a recursive tree structure from documents. This allows for more efficient and context-aware information retrieval across large texts, addressing common limitations in traditional language models. \n\n\n\nFor detailed methodologies and implementations, refer to the original paper:\n\n- [RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval](https://arxiv.org/abs/2401.18059)\n\n[![Paper page](https://huggingface.co/datasets/huggingface/badges/resolve/main/paper-page-sm.svg)](https://huggingface.co/papers/2401.18059)\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/raptor-recursive-abstractive-processing-for/question-answering-on-quality)](https://paperswithcode.com/sota/question-answering-on-quality?p=raptor-recursive-abstractive-processing-for)\n\n## Installation\n\nBefore using RAPTOR, ensure Python 3.8+ is installed. Clone the RAPTOR repository and install necessary dependencies:\n\n```bash\ngit clone https://github.com/parthsarthi03/raptor.git\ncd raptor\npip install -r requirements.txt\n```\n\n## Basic Usage\n\nTo get started with RAPTOR, follow these steps:\n\n### Setting Up RAPTOR\n\nFirst, set your OpenAI API key and initialize the RAPTOR configuration:\n\n```python\nimport os\nos.environ[\"OPENAI_API_KEY\"] = \"your-openai-api-key\"\n\nfrom raptor import RetrievalAugmentation\n\n# Initialize with default configuration. For advanced configurations, check the documentation. [WIP]\nRA = RetrievalAugmentation()\n```\n\n### Adding Documents to the Tree\n\nAdd your text documents to RAPTOR for indexing:\n\n```python\nwith open('sample.txt', 'r') as file:\n    text = file.read()\nRA.add_documents(text)\n```\n\n### Answering Questions\n\nYou can now use RAPTOR to answer questions based on the indexed documents:\n\n```python\nquestion = \"How did Cinderella reach her happy ending?\"\nanswer = RA.answer_question(question=question)\nprint(\"Answer: \", answer)\n```\n\n### Saving and Loading the Tree\n\nSave the constructed tree to a specified path:\n\n```python\nSAVE_PATH = \"demo/cinderella\"\nRA.save(SAVE_PATH)\n```\n\nLoad the saved tree back into RAPTOR:\n\n```python\nRA = RetrievalAugmentation(tree=SAVE_PATH)\nanswer = RA.answer_question(question=question)\n```\n\n\n### Extending RAPTOR with other Models\n\nRAPTOR is designed to be flexible and allows you to integrate any models for summarization, question-answering (QA), and embedding generation. Here is how to extend RAPTOR with your own models:\n\n#### Custom Summarization Model\n\nIf you wish to use a different language model for summarization, you can do so by extending the `BaseSummarizationModel` class. Implement the `summarize` method to integrate your custom summarization logic:\n\n```python\nfrom raptor import BaseSummarizationModel\n\nclass CustomSummarizationModel(BaseSummarizationModel):\n    def __init__(self):\n        # Initialize your model here\n        pass\n\n    def summarize(self, context, max_tokens=150):\n        # Implement your summarization logic here\n        # Return the summary as a string\n        summary = \"Your summary here\"\n        return summary\n```\n\n#### Custom QA Model\n\nFor custom QA models, extend the `BaseQAModel` class and implement the `answer_question` method. This method should return the best answer found by your model given a context and a question:\n\n```python\nfrom raptor import BaseQAModel\n\nclass CustomQAModel(BaseQAModel):\n    def __init__(self):\n        # Initialize your model here\n        pass\n\n    def answer_question(self, context, question):\n        # Implement your QA logic here\n        # Return the answer as a string\n        answer = \"Your answer here\"\n        return answer\n```\n\n#### Custom Embedding Model\n\nTo use a different embedding model, extend the `BaseEmbeddingModel` class. Implement the `create_embedding` method, which should return a vector representation of the input text:\n\n```python\nfrom raptor import BaseEmbeddingModel\n\nclass CustomEmbeddingModel(BaseEmbeddingModel):\n    def __init__(self):\n        # Initialize your model here\n        pass\n\n    def create_embedding(self, text):\n        # Implement your embedding logic here\n        # Return the embedding as a numpy array or a list of floats\n        embedding = [0.0] * embedding_dim  # Replace with actual embedding logic\n        return embedding\n```\n\n#### Integrating Custom Models with RAPTOR\n\nAfter implementing your custom models, integrate them with RAPTOR as follows:\n\n```python\nfrom raptor import RetrievalAugmentation, RetrievalAugmentationConfig\n\n# Initialize your custom models\ncustom_summarizer = CustomSummarizationModel()\ncustom_qa = CustomQAModel()\ncustom_embedding = CustomEmbeddingModel()\n\n# Create a config with your custom models\ncustom_config = RetrievalAugmentationConfig(\n    summarization_model=custom_summarizer,\n    qa_model=custom_qa,\n    embedding_model=custom_embedding\n)\n\n# Initialize RAPTOR with your custom config\nRA = RetrievalAugmentation(config=custom_config)\n```\n\nCheck out `demo.ipynb` for examples on how to specify your own summarization/QA models, such as Llama/Mistral/Gemma, and Embedding Models such as SBERT, for use with RAPTOR.\n\nNote: More examples and ways to configure RAPTOR are forthcoming. Advanced usage and additional features will be provided in the documentation and repository updates.\n\n## Contributing\n\nRAPTOR is an open-source project, and contributions are welcome. Whether you're fixing bugs, adding new features, or improving documentation, your help is appreciated.\n\n## License\n\nRAPTOR is released under the MIT License. See the LICENSE file in the repository for full details.\n\n## Citation\n\nIf RAPTOR assists in your research, please cite it as follows:\n\n```bibtex\n@inproceedings{sarthi2024raptor,\n    title={RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval},\n    author={Sarthi, Parth and Abdullah, Salman and Tuli, Aditi and Khanna, Shubh and Goldie, Anna and Manning, Christopher D.},\n    booktitle={International Conference on Learning Representations (ICLR)},\n    year={2024}\n}\n```\n\nStay tuned for more examples, configuration guides, and updates.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparthsarthi03%2Fraptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparthsarthi03%2Fraptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparthsarthi03%2Fraptor/lists"}