Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuilding code and db locally I get error #13

Open
jfkproductions opened this issue Aug 1, 2024 · 2 comments
Open

Rebuilding code and db locally I get error #13

jfkproductions opened this issue Aug 1, 2024 · 2 comments

Comments

@jfkproductions
Copy link

jfkproductions commented Aug 1, 2024

2024-08-01 16:13:27.848 Uncaught app exception
Traceback (most recent call last):
  File "C:\Users\KraaiduToit\AppData\Local\Programs\Python\Python312\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)
  File "C:\1.Pvt\1.Projects\llm-chatbot-python\bot.py", line 4, in <module>
    from agent import generate_response
  File "C:\1.Pvt\1.Projects\llm-chatbot-python\agent.py", line 13, in <module>
    from tools.vector import get_movie_plot
  File "C:\1.Pvt\1.Projects\llm-chatbot-python\tools\vector.py", line 19, in <module>
    neo4jvector = Neo4jVector.from_existing_index(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KraaiduToit\AppData\Local\Programs\Python\Python312\Lib\site-packages\langchain_community\vectorstores\neo4j_vector.py", line 1209, in from_existing_index
    raise ValueError(
ValueError: The specified vector index name does not exist. Make sure to check if you spelled it correctly
2024-08-01 16:13:27.849 Uncaught app exception
Traceback (most recent call last):
  File "C:\Users\KraaiduToit\AppData\Local\Programs\Python\Python312\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)
  File "C:\1.Pvt\1.Projects\llm-chatbot-python\bot.py", line 4, in <module>
    from agent import generate_response
ImportError: cannot import name 'generate_response' from 'agent' (C:\1.Pvt\1.Projects\llm-chatbot-python\agent.py)
2024-08-01 16:13:27.849 Uncaught app exception
Traceback (most recent call last):
  File "C:\Users\KraaiduToit\AppData\Local\Programs\Python\Python312\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)
  File "C:\1.Pvt\1.Projects\llm-chatbot-python\bot.py", line 4, in <module>
    from agent import generate_response
ImportError: cannot import name 'generate_response' from 'agent' (C:\1.Pvt\1.Projects\llm-chatbot-python\agent.py)

which suggest the index does not exist if i do a show indexes I do see my index moviePlots did i recreate it wrongly if so how can I fix this

image

here is he vectopr.py I am using

import streamlit as st
from llm import llm, embeddings
from graph import graph

# tag::import_vector[]
from langchain_community.vectorstores.neo4j_vector import Neo4jVector
# end::import_vector[]
# tag::import_chain[]
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain.chains import create_retrieval_chain
# end::import_chain[]

# tag::import_chat_prompt[]
from langchain_core.prompts import ChatPromptTemplate
# end::import_chat_prompt[]


# tag::vector[]
neo4jvector = Neo4jVector.from_existing_index(
    embeddings,                              # <1>
    graph=graph,                             # <2>
    index_name="moviePlots",                 # <3>
    node_label="Movie",                      # <4>
    text_node_property="plot",               # <5>
    embedding_node_property="plotEmbedding", # <6>
    retrieval_query="""
RETURN
    node.plot AS text,
    score,
    {
        title: node.title,
        directors: [ (person)-[:DIRECTED]->(node) | person.name ],
        actors: [ (person)-[r:ACTED_IN]->(node) | [person.name, r.role] ],
        tmdbId: node.tmdbId,
        source: 'https://www.themoviedb.org/movie/'+ node.tmdbId
    } AS metadata
"""
)
# end::vector[]

# tag::retriever[]
retriever = neo4jvector.as_retriever()
# end::retriever[]

# tag::prompt[]
instructions = (
    "Use the given context to answer the question."
    "If you don't know the answer, say you don't know."
    "Context: {context}"
)

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", instructions),
        ("human", "{input}"),
    ]
)
# end::prompt[]

# tag::chain[]
question_answer_chain = create_stuff_documents_chain(llm, prompt)
plot_retriever = create_retrieval_chain(
    retriever, 
    question_answer_chain
)
# end::chain[]

# tag::get_movie_plot[]
def get_movie_plot(input):
    return plot_retriever.invoke({"input": input})
# end::get_movie_plot[]
@martinohanlon
Copy link
Contributor

I have edited your issue to format the code. It was really difficult to read otherwise.

@martinohanlon
Copy link
Contributor

The code and index both look ok. Are you sure your Python program is connecting to the same database?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants