上传文件至 kg_lab_6.13
6.17 更新对检索工程数据复杂表达式的能力
This commit is contained in:
@@ -1,12 +1,49 @@
|
||||
import os
|
||||
from langchain_community.vectorstores import FAISS
|
||||
from langchain_huggingface import HuggingFaceEmbeddings
|
||||
from langchain.embeddings.base import Embeddings
|
||||
from openai import OpenAI
|
||||
import requests
|
||||
import httpx
|
||||
import logging
|
||||
|
||||
class SiliconFlowEmbeddings(Embeddings):
|
||||
"""SiliconFlow嵌入模型封装"""
|
||||
def __init__(self, api_key: str, model: str = "bge-m3"):
|
||||
self.api_key = api_key
|
||||
self.model = model
|
||||
self.url = "http://10.1.16.39:9995/v1/embeddings"
|
||||
self.headers = {
|
||||
"Authorization": f"Bearer {self.api_key}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
def _embed(self, input):
|
||||
payload = {
|
||||
"model": self.model,
|
||||
"input": input,
|
||||
"encoding_format": "float"
|
||||
}
|
||||
response = requests.post(self.url, json=payload, headers=self.headers)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return [item["embedding"] for item in data["data"]]
|
||||
|
||||
def embed_documents(self, texts):
|
||||
return self._embed(texts)
|
||||
|
||||
def embed_query(self, text):
|
||||
return self._embed([text])[0]
|
||||
|
||||
|
||||
# embeddings = Embedding(url="http://10.1.16.39:9995/v1", api_key="xxx", model_name="bge-m3")
|
||||
embeddings = SiliconFlowEmbeddings(api_key="xxx")
|
||||
|
||||
with open("./data/data.txt", 'r', encoding='utf-8') as file:
|
||||
txt_list = [line.strip() for line in file]
|
||||
|
||||
embedding_path = "/data/Z_LLM_data/Embed_data/bge-m3"
|
||||
embeddings = HuggingFaceEmbeddings(model_name=embedding_path)
|
||||
# embedding_path = "/data/Z_LLM_data/Embed_data/bge-m3"
|
||||
# embeddings = HuggingFaceEmbeddings(model_name=embedding_path)
|
||||
|
||||
faiss_archived = "./data/faiss_data/data"
|
||||
vectorstore_txt_faiss = FAISS.from_texts(txt_list, embeddings)
|
||||
|
||||
Reference in New Issue
Block a user