以编程方式使用文档

Galaxia 是一个 GraphRAG 解决方案,可自动处理文档、创建知识库(图语言模型)和检索: galaxia-rag

要使用 Galaxia,首先在此处上传文本并创建图语言模型: smabbler-cloud

模型构建并激活后,您将能够使用此集成来检索所需内容。

模块仓库位于此处: github

集成详情

检索器自托管云服务
Galaxia 检索器__langchain-galaxia-retriever__

设置

在检索任何内容之前,您需要在此处创建图语言模型: smabbler-cloud

按照以下 3 个简单步骤: rag-instruction

构建模型后不要忘记激活它!

安装

检索器在以下包中实现: pypi

pip install -qU langchain-galaxia-retriever

实例化

from langchain_galaxia_retriever.retriever import GalaxiaRetriever

gr = GalaxiaRetriever(
    api_url="beta.api.smabbler.com",
    api_key="<key>",  # you can find it here: https://beta.cloud.smabbler.com/user/account
    knowledge_base_id="<knowledge_base_id>",  # you can find it in https://beta.cloud.smabbler.com , in the model table
    n_retries=10,
    wait_time=5,
)

用法

result = gr.invoke("<test question>")
print(result)

在链中使用

# | output: false
# | echo: false

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0)
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough

prompt = ChatPromptTemplate.from_template(
    """Answer the question based only on the context provided.

Context: {context}

Question: {question}"""
)


def format_docs(docs):
    return "\n\n".join(doc.page_content for doc in docs)


chain = (
    {"context": gr | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)
chain.invoke("<test question>")

API 参考

有关 Galaxia 检索器的更多信息,请查看其在 GitHub