はじめに
In this post, I created a knowledge graph as a starting point for building a RAG system. After trying several different LLMs, only gpt-4o and gpt-4o-mini worked properly. In a recent this post, I summarized the installation and activation of ollama.
I created a knowledge graph using ollama this time, and I summarize its contents here. I hope this will be helpful, as I got into a bit of trouble in some areas.
Sources
- Implementing RAG with Knowledge Graph in LangChain Part 1 - Based on the code in the article also referenced in this post, I made changes to make it compatible with ollama.
- Building a local GraphRAG environment with Llama 3.2 and Neo4j - I referred to the section on creating vector indexes.
- ValueError: Index with name vector already exists - information I referenced to deal with an error I ran into.
Changed code
Only the parts that were changed from the code in the article in Source 1. are listed; see this post for more information on building ollama.
# ollama(gemma-2-2b-jpn)をLLMとして設定
from langchain_ollama.llms import OllamaLLM
llm = OllamaLLM(base_url = "http://192.168.11.4:11434", model="schroneko/gemma-2-2b-jpn-it", temperature=0)
Create vector index with Neo4jVector()
from langchain_ollama import OllamaEmbeddings
# ollama embeddings
embeddings = OllamaEmbeddings(
model="mxbai-embed-large",
base_url = "http://192.168.11.4:11434",
)
from langchain.vectorstores import Neo4jVector
vector_index = Neo4jVector.from_existing_graph(
embeddings,
search_type="hybrid",
node_label="Document",
text_node_properties=["text"],
embedding_node_property="embedding"
)
After entering the ollama container, I pulled the “maxbai-embed-large” used in the embedding model as follows.
# ollama pull mxbai-embed-large
Error in Neo4jVector()
The following error occurred in the above code “vector_index = Neo4jVector.from_existing_graph()”.
ValueError: Index with name vector already exists.The provided embedding function and vector index dimensions do not match.
Embedding function dimension: 1024
Vector index dimension: 1536
When I ran this article, I used gpt-4o-mini. The dimension of embeddings in OpenAI is 1536 and the dimension of embeddings in this case is 1024 and the above error occurred.
Coping with the error
Referring to the information source 3, I addressed the error as follows.
Connected to Neo4j from a browser and executed the following command from the browser. (“neo4j$” is the prompt)
neo4j$ drop index vector
Summary
Next, I would like to create a knowledge graph using wikipedia data and compare the results with the results of running other methods such as vector searches.