### Install LatticeDB via CLI, Python, or Node.js Source: https://latticedb.org Installation commands for different environments. ```shell curl -fsSL https://raw.githubusercontent.com/jeffhajewski/latticedb/main/dist/install.sh | bash ``` ```python pip install latticedb ``` ```javascript npm install @hajewski/latticedb ``` -------------------------------- ### Initialize and Query LatticeDB in Python Source: https://latticedb.org Setup a database instance, perform transactional writes, and execute a vector-similarity query. ```python from latticedb import Database from latticedb.embedding import hash_embed with Database("knowledge.db", create=True, enable_vectors=True, vector_dimensions=128) as db: with db.write() as txn: alice = txn.create_node(labels=["Person"], properties={"name": "Alice"}) doc = txn.create_node(labels=["Document"], properties={"title": "Attention Is All You Need"}) chunk = txn.create_node(labels=["Chunk"], properties={"text": "Self-attention..."}) txn.set_vector(chunk.id, "embedding", hash_embed("transformer", dimensions=128)) txn.create_edge(chunk.id, doc.id, "PART_OF") txn.create_edge(doc.id, alice.id, "AUTHORED_BY") txn.commit() results = db.query(""" MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person) WHERE chunk.embedding <=> $query < 0.5 RETURN doc.title, chunk.text, author.name ORDER BY chunk.embedding <=> $query LIMIT 5 """, parameters={"query": hash_embed("attention mechanism", dimensions=128)}) for row in results: print(f"{row['doc.title']} by {row['author.name']}") ``` -------------------------------- ### Initialize and Query LatticeDB in TypeScript Source: https://latticedb.org Asynchronous database operations including node creation, edge linking, and vector-based querying. ```typescript import { Database } from "@hajewski/latticedb"; import { hashEmbed } from "@hajewski/latticedb/embedding"; const db = new Database("knowledge.db", { create: true, enableVectors: true, vectorDimensions: 128, }); await db.open(); await db.write(async (txn) => { const alice = await txn.createNode({ labels: ["Person"], properties: { name: "Alice" } }); const doc = await txn.createNode({ labels: ["Document"], properties: { title: "Attention Is All You Need" } }); const chunk = await txn.createNode({ labels: ["Chunk"], properties: { text: "Self-attention..." } }); await txn.setVector(chunk.id, "embedding", hashEmbed("transformer", 128)); await txn.createEdge(chunk.id, doc.id, "PART_OF"); await txn.createEdge(doc.id, alice.id, "AUTHORED_BY"); }); const results = await db.query( `MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person) WHERE chunk.embedding <=> $query < 0.5 RETURN doc.title, chunk.text, author.name ORDER BY chunk.embedding <=> $query LIMIT 5`, { query: hashEmbed("attention mechanism", 128) } ); for (const row of results.rows) { console.log(`${row["doc.title"]} by ${row["author.name"]}`); } await db.close(); ``` -------------------------------- ### Construct and Query Graph with Cypher Source: https://latticedb.org Basic Cypher statements to create nodes and relationships, followed by a retrieval query. ```cypher CREATE (alice:Person {name: "Alice"}) CREATE (doc:Document {title: "Attention Is All You Need"}) CREATE (c1:Chunk {text: "Self-attention..."}) CREATE (c2:Chunk {text: "Transformer blocks..."}) CREATE (c1)-[:PART_OF]->(doc) CREATE (c2)-[:PART_OF]->(doc) CREATE (doc)-[:AUTHORED_BY]->(alice) MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person) RETURN doc.title, chunk.text, author.name; ``` -------------------------------- ### Execute a multi-modal Cypher query Source: https://latticedb.org Perform vector similarity, full-text search, and graph traversal in a single query. ```cypher -- Find chunks similar to a query, traverse to their document, then to the author MATCH (chunk:Chunk)-[:PART_OF]->(doc:Document)-[:AUTHORED_BY]->(author:Person) WHERE chunk.embedding <=> $query_vector < 0.3 AND doc.content @@ "neural networks" RETURN doc.title, chunk.text, author.name ORDER BY chunk.embedding <=> $query_vector LIMIT 10 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.