Created
March 26, 2024 05:02
-
-
Save tslmy/f673779dd5bccfb454c9dd7da239be3a to your computer and use it in GitHub Desktop.
Script to reproduce the neo4j dimensionality mismatch issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from llama_index.core import ( | |
Settings, | |
SimpleDirectoryReader, | |
StorageContext, | |
VectorStoreIndex, | |
) | |
from llama_index.legacy.vector_stores import Neo4jVectorStore | |
from llama_index.llms.ollama import Ollama | |
Settings.llm = Ollama( | |
model="zephyr:7b-beta", | |
request_timeout=60, # secs | |
temperature=0.01, | |
additional_kwargs={ | |
"stop": ["Observation:", "<|user|>", "<|assistant|>", "<|SYSTEM|>"], | |
"seed": 42, | |
}, | |
) | |
if __name__ == "__main__": | |
vector_store = Neo4jVectorStore( | |
url="bolt://localhost:7689", | |
username="neo4j", | |
password="correct-horse-battery-staple", | |
# TODO: This seems to be not respected. | |
embedding_dimension=1000, | |
) | |
# By default, the model is 384-dimensional. | |
Settings.embed_model = "local" | |
documents = SimpleDirectoryReader(input_files=["document.txt"]).load_data() | |
print(f"A total of {len(documents)} documents loaded.") | |
index = VectorStoreIndex.from_documents( | |
documents=documents, | |
storage_context=StorageContext.from_defaults(vector_store=vector_store), | |
) | |
query_engine = index.as_query_engine() | |
response = query_engine.query("lorem ispum") | |
# "Index query vector has 384 dimensions, but indexed vectors have 1536." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment