You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
834 B
25 lines
834 B
|
|
import os
|
|
from langchain.vectorstores import Chroma
|
|
from langchain.embeddings import OpenAIEmbeddings
|
|
from langchain.text_splitter import CharacterTextSplitter
|
|
from langchain.document_loaders import TextLoader
|
|
|
|
base_path = os.environ.get('OPENAI_API_BASE', 'http://localhost:8080/v1')
|
|
|
|
# Load and process the text
|
|
loader = TextLoader('state_of_the_union.txt')
|
|
documents = loader.load()
|
|
|
|
text_splitter = CharacterTextSplitter(chunk_size=300, chunk_overlap=70)
|
|
texts = text_splitter.split_documents(documents)
|
|
|
|
# Embed and store the texts
|
|
# Supplying a persist_directory will store the embeddings on disk
|
|
persist_directory = 'db'
|
|
|
|
embedding = OpenAIEmbeddings(model="text-embedding-ada-002")
|
|
vectordb = Chroma.from_documents(documents=texts, embedding=embedding, persist_directory=persist_directory)
|
|
|
|
vectordb.persist()
|
|
vectordb = None |