Skip to main content
Open on GitHub

Clarifai

Clarifai is one of first deep learning platforms having been founded in 2013. Clarifai provides an AI platform with the full AI lifecycle for data exploration, data labeling, model training, evaluation and inference around images, video, text and audio data. In the LangChain ecosystem, as far as we're aware, Clarifai is the only provider that supports LLMs, embeddings and a vector store in one production scale platform, making it an excellent choice to operationalize your LangChain implementations.

Clarifai provides 1,000s of AI models for many different use cases. You can explore them here to find the one most suited for your use case. These models include those created by other providers such as OpenAI, Anthropic, Cohere, AI21, etc. as well as state of the art from open source such as Falcon, InstructorXL, etc. so that you build the best in AI into your products. You'll find these organized by the creator's user_id and into projects we call applications denoted by their app_id. Those IDs will be needed in additional to the model_id and optionally the version_id, so make note of all these IDs once you found the best model for your use case!

Also note that given there are many models for images, video, text and audio understanding, you can build some interested AI agents that utilize the variety of AI models as experts to understand those data types.

安装与设置

  • 安装 Python SDK:
pip install clarifai

注册 Clarifai 账户,然后从您的 安全设置 获取个人访问令牌,并将其设置为环境变量 (CLARIFAI_PAT)。

LLMs

要查找Clarifai平台上的LLM选择,您可以选择文本到文本模型类型 这里

from langchain_community.llms import Clarifai
llm = Clarifai(pat=CLARIFAI_PAT, user_id=USER_ID, app_id=APP_ID, model_id=MODEL_ID)
API 参考:Clarifai

有关更多详细信息,请参阅Clarifai LLM包装器的文档,其中提供了详细的操操作指南

嵌入模型

要查找Clarifai平台上的嵌入模型选择,请选择文本到嵌入模型类型 这里

LangChain 中有一个 Clarifai 嵌入模型,你可以通过以下方式访问:

from langchain_community.embeddings import ClarifaiEmbeddings
embeddings = ClarifaiEmbeddings(pat=CLARIFAI_PAT, user_id=USER_ID, app_id=APP_ID, model_id=MODEL_ID)
API 参考:ClarifaiEmbeddings

查看一个 使用示例

向量存储

Clarifai的向量数据库于2016年推出,并已优化以支持实时搜索查询。通过Clarifai平台的工作流,您的数据将自动由嵌入模型索引,也可选择其他模型进一步索引信息到数据库中用于搜索。您不仅可以使用向量查询数据库,还可以根据元数据匹配、其他AI预测概念进行筛选,甚至执行地理坐标搜索。只需创建一个应用,为您的数据类型选择合适的基础工作流,然后上传数据(通过API按此处文档所述操作,或通过clarifai.com的用户界面)。

你还可以直接从 LangChain 添加数据,自动索引将为你完成。你会注意到,这与其他向量存储有所不同,在其他向量存储中,你需要在构造函数中提供嵌入模型,并让 LangChain 协调从文本获取嵌入并将其写入索引。不仅更加方便,而且使用 Clarifai 的分布式云在后台进行索引,可扩展性要强得多。

from langchain_community.vectorstores import Clarifai
clarifai_vector_db = Clarifai.from_texts(user_id=USER_ID, app_id=APP_ID, texts=texts, pat=CLARIFAI_PAT, number_of_docs=NUMBER_OF_DOCS, metadatas = metadatas)
API 参考:Clarifai

有关更多详细信息,请参阅Clarifai向量存储文档,其中提供了< a t="C0">详细的操操作指南。