mirror of
https://github.com/zylon-ai/private-gpt.git
synced 2025-12-22 07:40:12 +01:00
End-to-end working version
This commit is contained in:
parent
51dae80058
commit
55338b8f6e
6 changed files with 943 additions and 0 deletions
21
ingest.py
Normal file
21
ingest.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from langchain.document_loaders import TextLoader
|
||||
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
||||
from langchain.vectorstores import Chroma
|
||||
from langchain.embeddings import LlamaCppEmbeddings
|
||||
|
||||
def main():
|
||||
# Load document and split in chunks
|
||||
loader = TextLoader('./source_documents/state_of_the_union.txt', encoding='utf8')
|
||||
documents = loader.load()
|
||||
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
||||
texts = text_splitter.split_documents(documents)
|
||||
# Create embeddings
|
||||
llama = LlamaCppEmbeddings(model_path="./models/ggml-model-q4_0.bin")
|
||||
# Create and store locally vectorstore
|
||||
persist_directory = 'db'
|
||||
db = Chroma.from_documents(texts, llama, persist_directory=persist_directory)
|
||||
db.persist()
|
||||
db = None
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue