|
def train(): |
|
|
|
from langchain_community.document_loaders.csv_loader import CSVLoader |
|
from langchain.text_splitter import CharacterTextSplitter |
|
from langchain_openai import OpenAIEmbeddings |
|
from langchain_community.vectorstores.faiss import FAISS |
|
|
|
documents = CSVLoader(file_path="train/posts.csv").load() |
|
|
|
|
|
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=30) |
|
docs = text_splitter.split_documents(documents=documents) |
|
|
|
embeddings = OpenAIEmbeddings() |
|
|
|
vectorstore = FAISS.from_documents(docs, embeddings) |
|
|
|
vectorstore.save_local("_rise_product_db"); |
|
|
|
return {"trained":"success"} |