I am loading data from CSV file into graph DB. There are some text columns in the data that I would like to create embeddings for using local OllamaEmbeddingsCurrent code snippet:
from neo4j import GraphDatabase
from langchain_ollama import OllamaEmbeddings
def _generate_embeddings(txt: str) -> list:
"""Generate and store node embeddings for all nodes in the graph"""
model = OllamaEmbeddings(model=config.EMBEDDING_MODEL, base_url=config.OLLAMA_LOCAL_URI, num_ctx=config.OLLAMA_CONTEXT_LENGTH, num_gpu=1, temperature=0)
return model.embed_query(txt)
def load_graph_from_csv() -> None:
with driver.session(database="neo4j") as session:
query = f"""
LOAD CSV WITH HEADERS FROM '{Path(VISITS_CSV_PATH).as_uri()}' AS visits
MERGE (v:Visit {{id: toInteger(visits.visit_id),
room_number: toInteger(visits.room_number),
admission_type: visits.admission_type,
admission_date: visits.date_of_admission,
test_results: visits.test_results,
status: visits.visit_status
}})
ON CREATE SET v.chief_complaint = visits.chief_complaint
ON MATCH SET v.chief_complaint = visits.chief_complaint
ON CREATE SET v.treatment_description = visits.treatment_description
ON MATCH SET v.treatment_description = visits.treatment_description
ON CREATE SET v.diagnosis = visits.primary_diagnosis
ON MATCH SET v.diagnosis = visits.primary_diagnosis
"""
_ = session.run(query, {})
How to extend this code to use OllamaEmbeddings to create embeddings for the text fields and add to the node?