Graph + Vector Search
CogDB supports storing vector embeddings directly on vertices, allowing you to run similarity searches that seamlessly feed into graph traversals.
Auto-Vectorize
CogDB can automatically add embeddings for all your graph nodes using its free embedding service (powered by bge-small-en-v1.5 by default). You don't need to generate or manage vectors yourself unless you want to.
from cog.torque import Graph
g = Graph("planets")
g.put("europa", "orbits", "jupiter")
g.put("titan", "orbits", "saturn")
# Automatically generate embeddings for all nodes
g.vectorize()
After calling vectorize(), similarity queries will even automatically embed unknown words at query time! You can also configure it to use third-party providers like OpenAI.
Manual Control: Vectors on Vertices
For advanced use cases, you can manually associate high-dimensional vectors (such as document embeddings generated by your own models) with any node in your graph. This combines the semantic understanding of a vector database with the explicit relationships of a graph database.
# Store custom embeddings for an item
g.put_embedding("item1", [0.1, 0.2, 0.3])
K-Nearest Neighbors Search
Once embeddings are stored, you can use the k_nearest method to find the most similar vertices in the graph.
# Find the 5 nearest items
g.v().k_nearest("item1", k=5).all()
Chaining Vector Search and Traversal
The true power of CogDB is the ability to pipe the results of a vector search directly into a graph traversal. You can filter similarity search results by the relationships they hold.
# Find similar items, then see who authored them
g.v().k_nearest("item1", k=5).inc("authored").all()