mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-07 22:11:51 +00:00
Add neo4j vector memory template (#12993)
This commit is contained in:
23
templates/neo4j-vector-memory/ingest.py
Normal file
23
templates/neo4j-vector-memory/ingest.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from pathlib import Path
|
||||
|
||||
from langchain.document_loaders import TextLoader
|
||||
from langchain.embeddings.openai import OpenAIEmbeddings
|
||||
from langchain.text_splitter import TokenTextSplitter
|
||||
from langchain.vectorstores import Neo4jVector
|
||||
|
||||
txt_path = Path(__file__).parent / "dune.txt"
|
||||
|
||||
# Load the text file
|
||||
loader = TextLoader(str(txt_path))
|
||||
raw_documents = loader.load()
|
||||
|
||||
# Define chunking strategy
|
||||
splitter = TokenTextSplitter(chunk_size=512, chunk_overlap=24)
|
||||
documents = splitter.split_documents(raw_documents)
|
||||
|
||||
# Calculate embedding values and store them in the graph
|
||||
Neo4jVector.from_documents(
|
||||
documents,
|
||||
OpenAIEmbeddings(),
|
||||
index_name="dune",
|
||||
)
|
Reference in New Issue
Block a user