9. What are vector embeddings
Neo4j Inc. All rights reserved 2023
● Same concepts, just “an arrow”
● 100s or 1000s dimensions
● Each dimension corresponds to an
interesting feature or characteristic
10. Neighborhoods
Neo4j Inc. All rights reserved 2023
● cosine
● direction / angle based
vector point
query
nearest 4
● Euclidean
● distance based
11. Vector index
Neo4j Inc. All rights reserved 2023
● Queries can become expensive
○ need to compare every vector to the query
● Indexes make them quicker
○ like an index in a book, jumping right where you need
● Approximate nearest neighbour (k-ANN)
○ give me the 20 closest vectors to this one
13. Data -> Vectors?
Neo4j Inc. All rights reserved 2023
● Generate some vector embeddings
● Several models to meet your requirements
● Store on a node property
15. APOC example
WITH "<apiKey>" as apiKey
MATCH (d:Document)
WITH apiKey, a
CALL {
WITH apiKey, a
CALL apoc.ml.openai.embedding([d.text], apiKey, {}) yield index, text, embedding
CALL db.create.setNodeVectorProperty(d, 'textEmbedding', embedding)
RETURN d as doc
}
RETURN doc{.*};
16. Create and query vector index
CALL db.index.vector.createNodeIndex('document-embeddings', 'Document',
'textEmbedding', 1536, 'cosine');
CALL db.index.vector.queryNodes('document-embeddings', 10, $queryVector)
YIELD node AS similarDocuments, score
MATCH (similarDocuments)<-[:HAS]-(c:Company)
RETURN c.companyName as companyName, avg(score) AS score
ORDER BY score DESC LIMIT 10
17. How to use the vector index
Neo4j Inc. All rights reserved 2023
CALL db.index.vector.createNodeIndex(
'index-name', 'Label', 'propertyKey', 1536, 'cosine')
CALL db.index.vector.queryNodes('index-name', 1000, $queryVector)
valid:
● 'euclidean'
● 'cosine'
OpenAI gen2
dimensions
same name
nearest 1000
to queryVector
● parameter
● alias
● property
● manually typed
😬 good luck
Full documentation in Cypher manual
https://neo4j.com/docs/cypher-manual/current/indexes-for-vector-search/
18. Use LLM with Graph
Vector Search
To Harness Relevant and Contextual
Responses…
19. RAG enables…
Natural language
search on factual
information
retrieved from a
database
Prompt +
Relevant
Information
LLM API LLM
Chat API
User
Database
Search
Prompt Response
Relevant Results
/ Documents
2
3
1
Database
Retrieval Augmented Generation
19 Neo4j Inc. All rights reserved 2023
20. Graph + Vector = Semantic Search
Neo4j Inc. All rights reserved 2023
Find similar documents.
Find related information.
Combine for more
accurate results within a
relevant context.
Vector Index
Graph Structure
Knowledge Graph
Similarity Search
Pattern Matching
Retrieve relevant documents using LLM embeddings & vector search
Combine relevant documents with prompt
Instruct LLM to only use the relevant documents to generate response
Question: Are there any employees mentioned who work at 2 different companies?Question: Which managers with a Chicago address own companies?
Question: Which companies are vulnerable to lithium shortage?
Question: Which manager has the most Amazon holdings?