mirror of
https://github.com/langchain-ai/neo4j-semantic-layer.git
synced 2026-07-01 17:04:15 -04:00
Read only demo database
This commit is contained in:
@@ -14,7 +14,7 @@ from neo4j_semantic_layer.memory_tool import MemoryTool
|
||||
from neo4j_semantic_layer.recommendation_tool import RecommenderTool
|
||||
|
||||
llm = ChatOpenAI(temperature=0, model="gpt-4")
|
||||
tools = [InformationTool(), RecommenderTool(), MemoryTool()]
|
||||
tools = [InformationTool(), RecommenderTool()]# MemoryTool()]
|
||||
|
||||
llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools])
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ def remove_lucene_chars(text: str) -> str:
|
||||
return text.strip()
|
||||
|
||||
|
||||
def generate_full_text_query(input: str) -> str:
|
||||
def generate_full_text_query(input: str, type: str) -> str:
|
||||
"""
|
||||
Generate a full-text search query for a given input string.
|
||||
|
||||
@@ -51,11 +51,12 @@ def generate_full_text_query(input: str) -> str:
|
||||
operator. Useful for mapping movies and people from user questions
|
||||
to database values, and allows for some misspelings.
|
||||
"""
|
||||
property_map = {'movie': 'title', 'person': 'name'}
|
||||
full_text_query = ""
|
||||
words = [el for el in remove_lucene_chars(input).split() if el]
|
||||
for word in words[:-1]:
|
||||
full_text_query += f" {word}~0.8 AND"
|
||||
full_text_query += f" {words[-1]}~0.8"
|
||||
full_text_query += f" {property_map[type]}:{word}~0.8 AND"
|
||||
full_text_query += f" {property_map[type]}:{words[-1]}~0.8"
|
||||
return full_text_query.strip()
|
||||
|
||||
|
||||
@@ -77,8 +78,8 @@ def get_candidates(input: str, type: str, limit: int = 3) -> List[Dict[str, str]
|
||||
matching the query, with each candidate being a dictionary containing their name
|
||||
(or title) and label (either 'Person' or 'Movie').
|
||||
"""
|
||||
ft_query = generate_full_text_query(input)
|
||||
ft_query = generate_full_text_query(input, type)
|
||||
candidates = graph.query(
|
||||
candidate_query, {"fulltextQuery": ft_query, "index": type, "limit": limit}
|
||||
candidate_query, {"fulltextQuery": ft_query, "index": type + 'Fulltext', "limit": limit}
|
||||
)
|
||||
return candidates
|
||||
|
||||
Reference in New Issue
Block a user