from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings from langchain.text_splitter import CharacterTextSplitter from langchain.vectorstores import Chroma from langchain.document_loaders import TextLoader # load the document and split it into chunks loader = TextLoader("") documents = loader.load() len(documents) print(documents[0]) # split it into chunks text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) docs = text_splitter.split_documents(documents) len(docs) print(docs[0]) # create the open-source embedding function embedding_function = HuggingFaceEmbeddings # load it into Chroma db = Chroma.from_documents(docs, embedding_function, persist_directory="./chroma_db") # query it #query = "Question" #docs = db.similarity_search(query) # print results print(docs[0].page_content) docs = db2.similarity_search(query)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter