mirror of
https://github.com/hwchase17/langchain.git
synced 2025-04-28 03:51:50 +00:00
Galaxia integration (#30792)
- [ ] **PR title**: "docs: adding Smabbler's Galaxia integration" - [ ] **PR message**: **Twitter handle:** @Galaxia_graph I'm adding docs here + added the package to the packages.yml. I didn't add a unit test, because this integration is just a thin wrapper on top of our API. There isn't much left to test if you mock it away. --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
ca39680d2a
commit
60d8ade078
32
docs/docs/integrations/providers/galaxia.mdx
Normal file
32
docs/docs/integrations/providers/galaxia.mdx
Normal file
@ -0,0 +1,32 @@
|
||||
# Smabbler
|
||||
> Smabbler’s graph-powered platform boosts AI development by transforming data into a structured knowledge foundation.
|
||||
|
||||
# Galaxia
|
||||
|
||||
> Galaxia Knowledge Base is an integrated knowledge base and retrieval mechanism for RAG. In contrast to standard solution, it is based on Knowledge Graphs built using symbolic NLP and Knowledge Representation solutions. Provided texts are analysed and transformed into Graphs containing text, language and semantic information. This rich structure allows for retrieval that is based on semantic information, not on vector similarity/distance.
|
||||
|
||||
Implementing RAG using Galaxia involves first uploading your files to [Galaxia](https://beta.cloud.smabbler.com/home), analyzing them there and then building a model (knowledge graph). When the model is built, you can use `GalaxiaRetriever` to connect to the API and start retrieving.
|
||||
|
||||
More information: [docs](https://smabbler.gitbook.io/smabbler)
|
||||
|
||||
## Installation
|
||||
```
|
||||
pip install langchain-galaxia-retriever
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
from langchain_galaxia_retriever.retriever import GalaxiaRetriever
|
||||
|
||||
gr = GalaxiaRetriever(
|
||||
api_url="beta.api.smabbler.com",
|
||||
api_key="<key>",
|
||||
knowledge_base_id="<knowledge_base_id>",
|
||||
n_retries=10,
|
||||
wait_time=5,
|
||||
)
|
||||
|
||||
result = gr.invoke('<test question>')
|
||||
print(result)
|
||||
|
213
docs/docs/integrations/retrievers/galaxia-retriever.ipynb
Normal file
213
docs/docs/integrations/retrievers/galaxia-retriever.ipynb
Normal file
@ -0,0 +1,213 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "2af1fec5-4ca6-4167-8ee1-13314aac3258",
|
||||
"metadata": {
|
||||
"vscode": {
|
||||
"languageId": "raw"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"---\n",
|
||||
"sidebar_label: Galaxia\n",
|
||||
"---"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1d7d6cbc-4373-4fb5-94dd-acd610165452",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Galaxia Retriever\n",
|
||||
"\n",
|
||||
"Galaxia is GraphRAG solution, which automates document processing, knowledge base (Graph Language Model) creation and retrieval:\n",
|
||||
"[galaxia-rag](https://smabbler.gitbook.io/smabbler/api-rag/smabblers-api-rag)\n",
|
||||
"\n",
|
||||
"To use Galaxia first upload your texts and create a Graph Language Model here: [smabbler-cloud](https://beta.cloud.smabbler.com)\n",
|
||||
"\n",
|
||||
"After the model is built and activated, you will be able to use this integration to retrieve what you need.\n",
|
||||
"\n",
|
||||
"The module repository is located here: [github](https://github.com/rrozanski-smabbler/galaxia-langchain)\n",
|
||||
"\n",
|
||||
"### Integration details\n",
|
||||
"| Retriever | Self-host | Cloud offering | Package |\n",
|
||||
"| :--- | :--- | :---: | :---: |\n",
|
||||
"[Galaxia Retriever](https://github.com/rrozanski-smabbler/galaxia-langchain) | ❌ | ✅ | __langchain-galaxia-retriever__ |"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "82fa1c05-c205-4429-a74c-e6c81c4e8611",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Setup\n",
|
||||
"Before you can retrieve anything you need to create your Graph Language Model here: [smabbler-cloud](https://beta.cloud.smabbler.com)\n",
|
||||
"\n",
|
||||
"following these 3 simple steps: [rag-instruction](https://smabbler.gitbook.io/smabbler/api-rag/build-rag-model-in-3-steps)\n",
|
||||
"\n",
|
||||
"Don't forget to activate the model after building it!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "91897867-eb39-4c3b-8df8-5427043ecdcd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Installation\n",
|
||||
"The retriever is implemented in the following package: [pypi](https://pypi.org/project/langchain-galaxia-retriever/)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ceca36f2-013c-4b28-81fe-8808d0cf6419",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install -qU langchain-galaxia-retriever"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "019e0e50-5e66-440b-9cf1-d21b4009bf13",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Instantiation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c7188217-4b26-4201-b15a-b7a5f263f815",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_galaxia_retriever.retriever import GalaxiaRetriever\n",
|
||||
"\n",
|
||||
"gr = GalaxiaRetriever(\n",
|
||||
" api_url=\"beta.api.smabbler.com\",\n",
|
||||
" api_key=\"<key>\", # you can find it here: https://beta.cloud.smabbler.com/user/account\n",
|
||||
" knowledge_base_id=\"<knowledge_base_id>\", # you can find it in https://beta.cloud.smabbler.com , in the model table\n",
|
||||
" n_retries=10,\n",
|
||||
" wait_time=5,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "02d288a5-4f76-472e-9a60-eea8e6b8dc7a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Usage"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5f79e03f-77a6-4eb6-b41d-f3da2f897654",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"result = gr.invoke(\"<test question>\")\n",
|
||||
"print(result)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ffb2a595-a901-477a-a374-efd091bc1c9a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Use within a chain"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9c2e2394-ca33-47be-a851-551b4216daea",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# | output: false\n",
|
||||
"# | echo: false\n",
|
||||
"\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"\n",
|
||||
"llm = ChatOpenAI(model=\"gpt-3.5-turbo-0125\", temperature=0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ed8699d6-d65d-40ea-8c58-8d809cc512cf",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_core.output_parsers import StrOutputParser\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.runnables import RunnablePassthrough\n",
|
||||
"\n",
|
||||
"prompt = ChatPromptTemplate.from_template(\n",
|
||||
" \"\"\"Answer the question based only on the context provided.\n",
|
||||
"\n",
|
||||
"Context: {context}\n",
|
||||
"\n",
|
||||
"Question: {question}\"\"\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def format_docs(docs):\n",
|
||||
" return \"\\n\\n\".join(doc.page_content for doc in docs)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"chain = (\n",
|
||||
" {\"context\": gr | format_docs, \"question\": RunnablePassthrough()}\n",
|
||||
" | prompt\n",
|
||||
" | llm\n",
|
||||
" | StrOutputParser()\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f9b944d7-8800-4926-b1ce-fcdc52ecda1c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"chain.invoke(\"<test question>\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "11b5c9a5-0a66-415f-98f8-f12080cad30a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## API reference\n",
|
||||
"\n",
|
||||
"For more information about Galaxia Retriever check its implementation on github [github](https://github.com/rrozanski-smabbler/galaxia-langchain)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
@ -606,3 +606,7 @@ packages:
|
||||
- name: langchain-ydb
|
||||
path: .
|
||||
repo: ydb-platform/langchain-ydb
|
||||
- name: langchain-galaxia-retriever
|
||||
provider_page: galaxia
|
||||
path: .
|
||||
repo: rrozanski-smabbler/galaxia-langchain
|
||||
|
Loading…
Reference in New Issue
Block a user