TrustGraphGet Started

Collections (TrustGraph)

Logical groupings of related data in TrustGraph, allowing organization and isolation of documents, entities, and relationships into manageable sets.

TrustGraph Concepts

Collections in TrustGraph provide logical groupings of related data, enabling organization, access control, and isolation within a Knowledge Graph.

Creating Collections

// Create a collection
const hrCollection = await trustgraph.collections.create({
  name: "hr-documents",
  description: "Human resources documents and data",
  metadata: {
    department: "HR",
    classification: "confidential"
  },
  accessControl: {
    readers: ["hr-team", "executives"],
    writers: ["hr-admin"],
    admins: ["hr-director"]
  }
});

// Ingest into collection
await trustgraph.ingest({
  sources: ["hr-docs/"],
  collection: "hr-documents"
});

Querying Collections

// Query specific collection
const results = await trustgraph.query({
  collection: "hr-documents",
  query: "MATCH (p:Person)-[:REPORTS_TO]->(m:Manager) RETURN p, m"
});

// Query multiple collections
const combined = await trustgraph.query({
  collections: ["hr-documents", "org-chart"],
  query: "MATCH (n) RETURN n LIMIT 100"
});

// Cross-collection queries
const cross = await trustgraph.query({
  query: `
    MATCH (hr:Person) WHERE hr.collection = 'hr-documents'
    MATCH (sales:Person) WHERE sales.collection = 'sales-data'
    MATCH (hr)-[:COLLABORATED_WITH]->(sales)
    RETURN hr, sales
  `
});

Collection Management

// List collections
const collections = await trustgraph.collections.list();

// Get collection stats
const stats = await trustgraph.collections.stats("hr-documents");
console.log(stats);
// {
//   documents: 1250,
//   entities: 5420,
//   relationships: 12350,
//   size: "2.3 GB",
//   lastUpdated: "2024-12-20T10:30:00Z"
// }

// Archive collection
await trustgraph.collections.archive("old-data");

// Delete collection
await trustgraph.collections.delete("temp-collection");

Use Cases

1. Project Organization

// Separate collections per project
await trustgraph.collections.create({name: "project-alpha"});
await trustgraph.collections.create({name: "project-beta"});

// Each project has isolated data
await trustgraph.ingest({
  sources: ["alpha-docs/"],
  collection: "project-alpha"
});

2. Temporal Segmentation

// Collections for time periods
await trustgraph.collections.create({name: "q1-2024"});
await trustgraph.collections.create({name: "q2-2024"});
await trustgraph.collections.create({name: "q3-2024"});

// Query specific period
const q1Results = await trustgraph.query({
  collection: "q1-2024",
  query: "MATCH (n:Sale) RETURN sum(n.amount)"
});

3. Access Control

// Different access levels per collection
await trustgraph.collections.create({
  name: "public-data",
  accessControl: {
    readers: ["everyone"]
  }
});

await trustgraph.collections.create({
  name: "confidential",
  accessControl: {
    readers: ["executives", "compliance"],
    writers: ["cfo"],
    admins: ["ceo"]
  }
});

Collections vs Knowledge Cores

  • Collections: Organizational groupings within a graph
  • Knowledge Cores: Separate, swappable graph instances

Collections are lighter-weight and for logical organization. Knowledge Cores are for complete isolation.

See Also

Examples

  • Collection 'HR-Documents' containing employee records and org charts
  • Collection 'Q4-2024' containing quarterly financial reports

Related Terms

Learn More