| | class BaseLogger:
|
| | def __init__(self) -> None:
|
| | self.info = print
|
| |
|
| |
|
| | def extract_title_and_question(input_string):
|
| | lines = input_string.strip().split("\n")
|
| |
|
| | title = ""
|
| | question = ""
|
| | is_question = False
|
| |
|
| | for line in lines:
|
| | if line.startswith("Title:"):
|
| | title = line.split("Title: ", 1)[1].strip()
|
| | elif line.startswith("Question:"):
|
| | question = line.split("Question: ", 1)[1].strip()
|
| | is_question = (
|
| | True
|
| | )
|
| | elif is_question:
|
| |
|
| |
|
| | question += "\n" + line.strip()
|
| |
|
| | return title, question
|
| |
|
| |
|
| | def create_vector_index(driver, dimension: int) -> None:
|
| | index_query = "CALL db.index.vector.createNodeIndex('stackoverflow', 'Question', 'embedding', $dimension, 'cosine')"
|
| | try:
|
| | driver.query(index_query, {"dimension": dimension})
|
| | except:
|
| | pass
|
| | index_query = "CALL db.index.vector.createNodeIndex('top_answers', 'Answer', 'embedding', $dimension, 'cosine')"
|
| | try:
|
| | driver.query(index_query, {"dimension": dimension})
|
| | except:
|
| | pass
|
| |
|
| |
|
| | def create_constraints(driver):
|
| | driver.query(
|
| | "CREATE CONSTRAINT question_id IF NOT EXISTS FOR (q:Question) REQUIRE (q.id) IS UNIQUE"
|
| | )
|
| | driver.query(
|
| | "CREATE CONSTRAINT answer_id IF NOT EXISTS FOR (a:Answer) REQUIRE (a.id) IS UNIQUE"
|
| | )
|
| | driver.query(
|
| | "CREATE CONSTRAINT user_id IF NOT EXISTS FOR (u:User) REQUIRE (u.id) IS UNIQUE"
|
| | )
|
| | driver.query(
|
| | "CREATE CONSTRAINT tag_name IF NOT EXISTS FOR (t:Tag) REQUIRE (t.name) IS UNIQUE"
|
| | ) |