|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "raw", |
| 5 | + "id": "2af1fec5-4ca6-4167-8ee1-13314aac3258", |
| 6 | + "metadata": { |
| 7 | + "vscode": { |
| 8 | + "languageId": "raw" |
| 9 | + } |
| 10 | + }, |
| 11 | + "source": [ |
| 12 | + "---\n", |
| 13 | + "sidebar_label: Galaxia\n", |
| 14 | + "---" |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "markdown", |
| 19 | + "id": "1d7d6cbc-4373-4fb5-94dd-acd610165452", |
| 20 | + "metadata": {}, |
| 21 | + "source": [ |
| 22 | + "# Galaxia Retriever\n", |
| 23 | + "\n", |
| 24 | + "Galaxia is GraphRAG solution, which automates document processing, knowledge base (Graph Language Model) creation and retrieval:\n", |
| 25 | + "[galaxia-rag](https://smabbler.gitbook.io/smabbler/api-rag/smabblers-api-rag)\n", |
| 26 | + "\n", |
| 27 | + "To use Galaxia first upload your texts and create a Graph Language Model here: [smabbler-cloud](https://beta.cloud.smabbler.com)\n", |
| 28 | + "\n", |
| 29 | + "After the model is built and activated, you will be able to use this integration to retrieve what you need.\n", |
| 30 | + "\n", |
| 31 | + "The module repository is located here: [github](https://github.com/rrozanski-smabbler/galaxia-langchain)\n", |
| 32 | + "\n", |
| 33 | + "### Integration details\n", |
| 34 | + "| Retriever | Self-host | Cloud offering | Package |\n", |
| 35 | + "| :--- | :--- | :---: | :---: |\n", |
| 36 | + "[Galaxia Retriever](https://github.com/rrozanski-smabbler/galaxia-langchain) | ❌ | ✅ | __langchain-galaxia-retriever__ |" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "markdown", |
| 41 | + "id": "82fa1c05-c205-4429-a74c-e6c81c4e8611", |
| 42 | + "metadata": {}, |
| 43 | + "source": [ |
| 44 | + "## Setup\n", |
| 45 | + "Before you can retrieve anything you need to create your Graph Language Model here: [smabbler-cloud](https://beta.cloud.smabbler.com)\n", |
| 46 | + "\n", |
| 47 | + "following these 3 simple steps: [rag-instruction](https://smabbler.gitbook.io/smabbler/api-rag/build-rag-model-in-3-steps)\n", |
| 48 | + "\n", |
| 49 | + "Don't forget to activate the model after building it!" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "id": "91897867-eb39-4c3b-8df8-5427043ecdcd", |
| 55 | + "metadata": {}, |
| 56 | + "source": [ |
| 57 | + "### Installation\n", |
| 58 | + "The retriever is implemented in the following package: [pypi](https://pypi.org/project/langchain-galaxia-retriever/)" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "code", |
| 63 | + "execution_count": null, |
| 64 | + "id": "ceca36f2-013c-4b28-81fe-8808d0cf6419", |
| 65 | + "metadata": {}, |
| 66 | + "outputs": [], |
| 67 | + "source": [ |
| 68 | + "%pip install -qU langchain-galaxia-retriever" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "markdown", |
| 73 | + "id": "019e0e50-5e66-440b-9cf1-d21b4009bf13", |
| 74 | + "metadata": {}, |
| 75 | + "source": [ |
| 76 | + "## Instantiation" |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + "cell_type": "code", |
| 81 | + "execution_count": null, |
| 82 | + "id": "c7188217-4b26-4201-b15a-b7a5f263f815", |
| 83 | + "metadata": {}, |
| 84 | + "outputs": [], |
| 85 | + "source": [ |
| 86 | + "from langchain_galaxia_retriever.retriever import GalaxiaRetriever\n", |
| 87 | + "\n", |
| 88 | + "gr = GalaxiaRetriever(\n", |
| 89 | + " api_url=\"beta.api.smabbler.com\",\n", |
| 90 | + " api_key=\"<key>\", # you can find it here: https://beta.cloud.smabbler.com/user/account\n", |
| 91 | + " knowledge_base_id=\"<knowledge_base_id>\", # you can find it in https://beta.cloud.smabbler.com , in the model table\n", |
| 92 | + " n_retries=10,\n", |
| 93 | + " wait_time=5,\n", |
| 94 | + ")" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "markdown", |
| 99 | + "id": "02d288a5-4f76-472e-9a60-eea8e6b8dc7a", |
| 100 | + "metadata": {}, |
| 101 | + "source": [ |
| 102 | + "## Usage" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
| 108 | + "id": "5f79e03f-77a6-4eb6-b41d-f3da2f897654", |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
| 112 | + "result = gr.invoke(\"<test question>\")\n", |
| 113 | + "print(result)" |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "markdown", |
| 118 | + "id": "ffb2a595-a901-477a-a374-efd091bc1c9a", |
| 119 | + "metadata": {}, |
| 120 | + "source": [ |
| 121 | + "## Use within a chain" |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "cell_type": "code", |
| 126 | + "execution_count": null, |
| 127 | + "id": "9c2e2394-ca33-47be-a851-551b4216daea", |
| 128 | + "metadata": {}, |
| 129 | + "outputs": [], |
| 130 | + "source": [ |
| 131 | + "# | output: false\n", |
| 132 | + "# | echo: false\n", |
| 133 | + "\n", |
| 134 | + "from langchain_openai import ChatOpenAI\n", |
| 135 | + "\n", |
| 136 | + "llm = ChatOpenAI(model=\"gpt-3.5-turbo-0125\", temperature=0)" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "execution_count": null, |
| 142 | + "id": "ed8699d6-d65d-40ea-8c58-8d809cc512cf", |
| 143 | + "metadata": {}, |
| 144 | + "outputs": [], |
| 145 | + "source": [ |
| 146 | + "from langchain_core.output_parsers import StrOutputParser\n", |
| 147 | + "from langchain_core.prompts import ChatPromptTemplate\n", |
| 148 | + "from langchain_core.runnables import RunnablePassthrough\n", |
| 149 | + "\n", |
| 150 | + "prompt = ChatPromptTemplate.from_template(\n", |
| 151 | + " \"\"\"Answer the question based only on the context provided.\n", |
| 152 | + "\n", |
| 153 | + "Context: {context}\n", |
| 154 | + "\n", |
| 155 | + "Question: {question}\"\"\"\n", |
| 156 | + ")\n", |
| 157 | + "\n", |
| 158 | + "\n", |
| 159 | + "def format_docs(docs):\n", |
| 160 | + " return \"\\n\\n\".join(doc.page_content for doc in docs)\n", |
| 161 | + "\n", |
| 162 | + "\n", |
| 163 | + "chain = (\n", |
| 164 | + " {\"context\": gr | format_docs, \"question\": RunnablePassthrough()}\n", |
| 165 | + " | prompt\n", |
| 166 | + " | llm\n", |
| 167 | + " | StrOutputParser()\n", |
| 168 | + ")" |
| 169 | + ] |
| 170 | + }, |
| 171 | + { |
| 172 | + "cell_type": "code", |
| 173 | + "execution_count": null, |
| 174 | + "id": "f9b944d7-8800-4926-b1ce-fcdc52ecda1c", |
| 175 | + "metadata": {}, |
| 176 | + "outputs": [], |
| 177 | + "source": [ |
| 178 | + "chain.invoke(\"<test question>\")" |
| 179 | + ] |
| 180 | + }, |
| 181 | + { |
| 182 | + "cell_type": "markdown", |
| 183 | + "id": "11b5c9a5-0a66-415f-98f8-f12080cad30a", |
| 184 | + "metadata": {}, |
| 185 | + "source": [ |
| 186 | + "## API reference\n", |
| 187 | + "\n", |
| 188 | + "For more information about Galaxia Retriever check its implementation on github [github](https://github.com/rrozanski-smabbler/galaxia-langchain)" |
| 189 | + ] |
| 190 | + } |
| 191 | + ], |
| 192 | + "metadata": { |
| 193 | + "kernelspec": { |
| 194 | + "display_name": "Python 3 (ipykernel)", |
| 195 | + "language": "python", |
| 196 | + "name": "python3" |
| 197 | + }, |
| 198 | + "language_info": { |
| 199 | + "codemirror_mode": { |
| 200 | + "name": "ipython", |
| 201 | + "version": 3 |
| 202 | + }, |
| 203 | + "file_extension": ".py", |
| 204 | + "mimetype": "text/x-python", |
| 205 | + "name": "python", |
| 206 | + "nbconvert_exporter": "python", |
| 207 | + "pygments_lexer": "ipython3", |
| 208 | + "version": "3.11.7" |
| 209 | + } |
| 210 | + }, |
| 211 | + "nbformat": 4, |
| 212 | + "nbformat_minor": 5 |
| 213 | +} |
0 commit comments