What are Entities?
Entities are named things (people, organizations, places, etc.) automatically extracted from your memories. They form the nodes of a knowledge graph that connects related information.
entity-example.json
// Entity extracted from memories
{
"id": "ent_abc123",
"name": "John Smith",
"type": "person",
"attributes": {
"role": "colleague",
"department": "Engineering"
},
"aliases": ["John", "JS"],
"mention_count": 15
}Entity Types
Entities are classified into types:
person- People (colleagues, friends, contacts)organization- Companies, teams, groupslocation- Places, cities, addressesdate- Dates, time periodsproduct- Products, tools, softwareconcept- Abstract concepts, topicsevent- Meetings, conferences, milestonesskill- Technologies, abilities
Querying Entities
List and filter entities:
import { Trix } from '@trixdb/client';
const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });
// List all entities
const entities = await trix.entities.list();
// Filter by type
const people = await trix.entities.list({
type: 'person'
});
// Get entity details
const entity = await trix.entities.get('ent_abc123');
console.log(entity.name); // "John Smith"
console.log(entity.type); // "person"
console.log(entity.attributes); // { role: "colleague", ... }Entity Relationships
Entities are connected by relationships, forming a knowledge graph:
import { Trix } from '@trixdb/client';
const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });
// Get relationships for an entity
const relationships = await trix.entities.getRelationships('ent_abc123');
// Each relationship includes target entity and type
relationships.forEach(rel => {
console.log(`${rel.relationshipType}: ${rel.target.name}`);
console.log(`Strength: ${rel.strength}`);
});
// Example output:
// works_at: Google (strength: 0.95)
// knows: Jane Doe (strength: 0.8)Graph Traversal
Explore the knowledge graph with traversal operations:
import { Trix } from '@trixdb/client';
const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });
// Get subgraph around an entity (2-hop neighborhood)
const subgraph = await trix.graph.subgraph('ent_abc123', {
hops: 2
});
console.log(`Nodes: ${subgraph.nodes.length}`);
console.log(`Edges: ${subgraph.edges.length}`);
// Find path between two entities
const path = await trix.graph.findPath({
from: 'ent_abc123',
to: 'ent_xyz789'
});
// Show connection path
path.nodes.forEach((node, i) => {
if (i < path.edges.length) {
console.log(`${node.name} --[${path.edges[i].type}]--> `);
} else {
console.log(node.name);
}
});Graph traversal is useful for discovering indirect connections - like finding how two people might be connected through mutual contacts or organizations.
Entity Facts
Get all facts that mention a specific entity:
import { Trix } from '@trixdb/client';
const trix = new Trix({ apiKey: process.env.TRIX_API_KEY });
// Get facts mentioning an entity
const facts = await trix.entities.getFacts('ent_abc123');
// Display facts about John Smith
facts.forEach(fact => {
console.log(`[${fact.importance}] ${fact.content}`);
});
// Output:
// [8] John Smith works at Google
// [7] John Smith is based in San Francisco
// [6] John Smith loves Italian food