MCPcopy
hub / github.com/docker/genai-stack / insert_so_data

Function insert_so_data

loader.py:54–95  ·  view source on GitHub ↗
(data: dict)

Source from the content-addressed store, hash-verified

52
53
54def insert_so_data(data: dict) -> None:
55 # Calculate embedding values for questions and answers
56 for q in data["items"]:
57 question_text = q["title"] + "\n" + q["body_markdown"]
58 q["embedding"] = embeddings.embed_query(question_text)
59 for a in q["answers"]:
60 a["embedding"] = embeddings.embed_query(
61 question_text + "\n" + a["body_markdown"]
62 )
63
64 # Cypher, the query language of Neo4j, is used to import the data
65 # https://neo4j.com/docs/getting-started/cypher-intro/
66 # https://neo4j.com/docs/cypher-cheat-sheet/5/auradb-enterprise/
67 import_query = """
68 UNWIND $data AS q
69 MERGE (question:Question {id:q.question_id})
70 ON CREATE SET question.title = q.title, question.link = q.link, question.score = q.score,
71 question.favorite_count = q.favorite_count, question.creation_date = datetime({epochSeconds: q.creation_date}),
72 question.body = q.body_markdown, question.embedding = q.embedding
73 FOREACH (tagName IN q.tags |
74 MERGE (tag:Tag {name:tagName})
75 MERGE (question)-[:TAGGED]->(tag)
76 )
77 FOREACH (a IN q.answers |
78 MERGE (question)<-[:ANSWERS]-(answer:Answer {id:a.answer_id})
79 SET answer.is_accepted = a.is_accepted,
80 answer.score = a.score,
81 answer.creation_date = datetime({epochSeconds:a.creation_date}),
82 answer.body = a.body_markdown,
83 answer.embedding = a.embedding
84 MERGE (answerer:User {id:coalesce(a.owner.user_id, "deleted")})
85 ON CREATE SET answerer.display_name = a.owner.display_name,
86 answerer.reputation= a.owner.reputation
87 MERGE (answer)<-[:PROVIDED]-(answerer)
88 )
89 WITH * WHERE NOT q.owner.user_id IS NULL
90 MERGE (owner:User {id:q.owner.user_id})
91 ON CREATE SET owner.display_name = q.owner.display_name,
92 owner.reputation = q.owner.reputation
93 MERGE (owner)-[:ASKED]->(question)
94 """
95 neo4j_graph.query(import_query, {"data": data["items"]})
96
97
98# Streamlit

Callers 2

load_so_dataFunction · 0.85
load_high_score_so_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected