Skip to content

Commit 84a921f

Browse files
committed
Add community and covariate records for pipeline parity
1 parent 9a76e2b commit 84a921f

5 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Immutable;
2+
3+
namespace GraphRag.Community;
4+
5+
/// <summary>
6+
/// Represents a finalized community row emitted by the GraphRAG pipeline.
7+
/// </summary>
8+
public sealed record CommunityRecord(
9+
string Id,
10+
int HumanReadableId,
11+
int CommunityId,
12+
int Level,
13+
int? ParentId,
14+
ImmutableArray<int> Children,
15+
string Title,
16+
ImmutableArray<string> EntityIds,
17+
ImmutableArray<string> RelationshipIds,
18+
ImmutableArray<string> TextUnitIds,
19+
string? Period,
20+
int Size);

src/ManagedCode.GraphRag/Constants/PipelineTableNames.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ public static class PipelineTableNames
66
public const string TextUnits = "text_units";
77
public const string Entities = "entities";
88
public const string Relationships = "relationships";
9+
public const string Communities = "communities";
910
public const string CommunityReports = "community_reports";
11+
public const string Covariates = "covariates";
1012
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace GraphRag.Covariates;
2+
3+
/// <summary>
4+
/// Represents a finalized covariate (claim) row emitted by the GraphRAG pipeline.
5+
/// </summary>
6+
public sealed record CovariateRecord(
7+
string Id,
8+
int HumanReadableId,
9+
string CovariateType,
10+
string? Type,
11+
string? Description,
12+
string SubjectId,
13+
string? ObjectId,
14+
string? Status,
15+
string? StartDate,
16+
string? EndDate,
17+
string? SourceText,
18+
string TextUnitId);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Immutable;
2+
using System.Linq;
3+
using GraphRag.Community;
4+
using Xunit;
5+
6+
namespace ManagedCode.GraphRag.Tests.Community;
7+
8+
public sealed class CommunityRecordTests
9+
{
10+
[Fact]
11+
public void Constructor_PopulatesAllProperties()
12+
{
13+
var record = new CommunityRecord(
14+
Id: "community-uuid",
15+
HumanReadableId: 12,
16+
CommunityId: 42,
17+
Level: 3,
18+
ParentId: 7,
19+
Children: ImmutableArray.Create(8, 9),
20+
Title: "Energy Sector",
21+
EntityIds: ImmutableArray.Create("entity-1", "entity-2"),
22+
RelationshipIds: ImmutableArray.Create("rel-1"),
23+
TextUnitIds: ImmutableArray.Create("unit-1", "unit-2"),
24+
Period: "2024-05-01",
25+
Size: 18);
26+
27+
Assert.Equal("community-uuid", record.Id);
28+
Assert.Equal(12, record.HumanReadableId);
29+
Assert.Equal(42, record.CommunityId);
30+
Assert.Equal(3, record.Level);
31+
Assert.Equal(7, record.ParentId);
32+
Assert.Equal(new[] { 8, 9 }, record.Children.ToArray());
33+
Assert.Equal("Energy Sector", record.Title);
34+
Assert.Equal(new[] { "entity-1", "entity-2" }, record.EntityIds.ToArray());
35+
Assert.Equal(new[] { "rel-1" }, record.RelationshipIds.ToArray());
36+
Assert.Equal(new[] { "unit-1", "unit-2" }, record.TextUnitIds.ToArray());
37+
Assert.Equal("2024-05-01", record.Period);
38+
Assert.Equal(18, record.Size);
39+
}
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using GraphRag.Covariates;
2+
using Xunit;
3+
4+
namespace ManagedCode.GraphRag.Tests.Covariates;
5+
6+
public sealed class CovariateRecordTests
7+
{
8+
[Fact]
9+
public void Constructor_PopulatesAllProperties()
10+
{
11+
var record = new CovariateRecord(
12+
Id: "cov-1",
13+
HumanReadableId: 5,
14+
CovariateType: "claim",
15+
Type: "fraud",
16+
Description: "Alleged false reporting",
17+
SubjectId: "entity-1",
18+
ObjectId: "entity-2",
19+
Status: "SUSPECTED",
20+
StartDate: "2024-03-01",
21+
EndDate: "2024-04-01",
22+
SourceText: "Entity-1 may have misled Entity-2",
23+
TextUnitId: "unit-1");
24+
25+
Assert.Equal("cov-1", record.Id);
26+
Assert.Equal(5, record.HumanReadableId);
27+
Assert.Equal("claim", record.CovariateType);
28+
Assert.Equal("fraud", record.Type);
29+
Assert.Equal("Alleged false reporting", record.Description);
30+
Assert.Equal("entity-1", record.SubjectId);
31+
Assert.Equal("entity-2", record.ObjectId);
32+
Assert.Equal("SUSPECTED", record.Status);
33+
Assert.Equal("2024-03-01", record.StartDate);
34+
Assert.Equal("2024-04-01", record.EndDate);
35+
Assert.Equal("Entity-1 may have misled Entity-2", record.SourceText);
36+
Assert.Equal("unit-1", record.TextUnitId);
37+
}
38+
}

0 commit comments

Comments
 (0)