2023-09-15
embedding 模型有哪些?
主要有 OpenAI、Minimax、SentenceTransformer 库的all-MiniLM-L6-v2模型。下面一一介绍:
通过 langchain 调用:
from langchain.embeddings.openai import OpenAIEmbeddings
embedding_function = OpenAIEmbeddings(openai_api_key="your-api-key")
国产模型,收费。
通过 langchain 调用:
import os
os.environ["MINIMAX_GROUP_ID"] = "your-groupid"
os.environ["MINIMAX_API_KEY"] = "your-api-key"
from langchain.embeddings import MiniMaxEmbeddings
embeddings = MiniMaxEmbeddings()
Python 库,免费使用。
通过 langchain 调用:
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings
embedding_function = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
db = Chroma.from_documents(docs, embedding_function)
query = "血压高怎么办"
docs = db.similarity_search(query)
print(docs[0].page_content)