mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
fa5d49f2c1
ran ```bash g grep -l "langchain.vectorstores" | xargs -L 1 sed -i '' "s/langchain\.vectorstores/langchain_community.vectorstores/g" g grep -l "langchain.document_loaders" | xargs -L 1 sed -i '' "s/langchain\.document_loaders/langchain_community.document_loaders/g" g grep -l "langchain.chat_loaders" | xargs -L 1 sed -i '' "s/langchain\.chat_loaders/langchain_community.chat_loaders/g" g grep -l "langchain.document_transformers" | xargs -L 1 sed -i '' "s/langchain\.document_transformers/langchain_community.document_transformers/g" g grep -l "langchain\.graphs" | xargs -L 1 sed -i '' "s/langchain\.graphs/langchain_community.graphs/g" g grep -l "langchain\.memory\.chat_message_histories" | xargs -L 1 sed -i '' "s/langchain\.memory\.chat_message_histories/langchain_community.chat_message_histories/g" gco master libs/langchain/tests/unit_tests/*/test_imports.py gco master libs/langchain/tests/unit_tests/**/test_public_api.py ```
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from langchain_community.embeddings import OpenAIEmbeddings
|
|
from langchain_community.vectorstores import Neo4jVector
|
|
|
|
# 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,
|
|
)
|