2024-01-02 21:47:11 +00:00
|
|
|
from langchain_community.vectorstores import Neo4jVector
|
2024-03-30 14:40:05 +00:00
|
|
|
from langchain_openai import OpenAIEmbeddings
|
2023-11-03 20:22:55 +00:00
|
|
|
|
|
|
|
# Typical RAG retriever
|
|
|
|
|
|
|
|
typical_rag = Neo4jVector.from_existing_index(
|
|
|
|
OpenAIEmbeddings(), index_name="typical_rag"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Parent retriever
|
|
|
|
|
|
|
|
parent_query = """
|
|
|
|
MATCH (node)<-[:HAS_CHILD]-(parent)
|
|
|
|
WITH parent, max(score) AS score // deduplicate parents
|
|
|
|
RETURN parent.text AS text, score, {} AS metadata LIMIT 1
|
|
|
|
"""
|
|
|
|
|
|
|
|
parent_vectorstore = Neo4jVector.from_existing_index(
|
|
|
|
OpenAIEmbeddings(),
|
|
|
|
index_name="parent_document",
|
|
|
|
retrieval_query=parent_query,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Hypothetic questions retriever
|
|
|
|
|
|
|
|
hypothetic_question_query = """
|
|
|
|
MATCH (node)<-[:HAS_QUESTION]-(parent)
|
|
|
|
WITH parent, max(score) AS score // deduplicate parents
|
|
|
|
RETURN parent.text AS text, score, {} AS metadata
|
|
|
|
"""
|
|
|
|
|
|
|
|
hypothetic_question_vectorstore = Neo4jVector.from_existing_index(
|
|
|
|
OpenAIEmbeddings(),
|
|
|
|
index_name="hypothetical_questions",
|
|
|
|
retrieval_query=hypothetic_question_query,
|
|
|
|
)
|
|
|
|
# Summary retriever
|
|
|
|
|
|
|
|
summary_query = """
|
|
|
|
MATCH (node)<-[:HAS_SUMMARY]-(parent)
|
|
|
|
WITH parent, max(score) AS score // deduplicate parents
|
|
|
|
RETURN parent.text AS text, score, {} AS metadata
|
|
|
|
"""
|
|
|
|
|
|
|
|
summary_vectorstore = Neo4jVector.from_existing_index(
|
|
|
|
OpenAIEmbeddings(),
|
|
|
|
index_name="summary",
|
|
|
|
retrieval_query=summary_query,
|
|
|
|
)
|