Skip to content

Commit b8b9ae9

Browse files
committed
Update provider.ts
1 parent eefb154 commit b8b9ae9

File tree

1 file changed

+96
-2
lines changed

1 file changed

+96
-2
lines changed

packages/plugin-raggraph/src/provider.ts

+96-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
State,
77
} from "@ai16z/eliza";
88
import { createGraphRAG } from "./driver";
9-
import { GraphRAGResponse } from "./types";
9+
import {
10+
GraphRAGResponse,
11+
DocumentRelationType,
12+
NodeProperties,
13+
} from "./types";
1014
import NodeCache from "node-cache";
1115
import * as path from "path";
1216

@@ -68,6 +72,96 @@ export class RAGGraphProvider {
6872
async close(): Promise<void> {
6973
await this.graphRAG.close();
7074
}
75+
76+
async createVectorIndex(): Promise<void> {
77+
try {
78+
await this.graphRAG.createVectorIndex();
79+
} catch (error) {
80+
console.error("Error creating vector index:", error);
81+
throw error;
82+
}
83+
}
84+
85+
async addDocument(node: {
86+
id: string;
87+
title: string;
88+
content: string;
89+
connections?: Array<{
90+
nodeId: string;
91+
relationType: DocumentRelationType;
92+
direction: "from" | "to";
93+
}>;
94+
}): Promise<void> {
95+
try {
96+
await this.graphRAG.addDocument(node);
97+
} catch (error) {
98+
console.error("Error adding document:", error);
99+
throw error;
100+
}
101+
}
102+
103+
async getDocument(id: string): Promise<NodeProperties | null> {
104+
try {
105+
return await this.graphRAG.getDocument(id);
106+
} catch (error) {
107+
console.error("Error getting document:", error);
108+
throw error;
109+
}
110+
}
111+
112+
async updateDocument(
113+
id: string,
114+
updates: {
115+
title?: string;
116+
content?: string;
117+
}
118+
): Promise<void> {
119+
try {
120+
await this.graphRAG.updateDocument(id, updates);
121+
} catch (error) {
122+
console.error("Error updating document:", error);
123+
throw error;
124+
}
125+
}
126+
127+
async deleteDocument(id: string): Promise<void> {
128+
try {
129+
await this.graphRAG.deleteDocument(id);
130+
} catch (error) {
131+
console.error("Error deleting document:", error);
132+
throw error;
133+
}
134+
}
135+
136+
async addConnection(
137+
sourceId: string,
138+
targetId: string,
139+
relationType: DocumentRelationType
140+
): Promise<void> {
141+
try {
142+
await this.graphRAG.addConnection(sourceId, targetId, relationType);
143+
} catch (error) {
144+
console.error("Error adding connection:", error);
145+
throw error;
146+
}
147+
}
148+
149+
async deleteConnection(
150+
sourceId: string,
151+
targetId: string,
152+
relationType: DocumentRelationType
153+
): Promise<void> {
154+
try {
155+
await this.graphRAG.deleteConnection(
156+
sourceId,
157+
targetId,
158+
relationType
159+
);
160+
} catch (error) {
161+
console.error("Error deleting connection:", error);
162+
throw error;
163+
}
164+
}
71165
}
72166

73167
const ragGraphProvider: Provider = {
@@ -88,7 +182,7 @@ const ragGraphProvider: Provider = {
88182
runtime.cacheManager
89183
);
90184

91-
const response = await provider.query(message.content);
185+
const response = await provider.query(message.content.text);
92186
await provider.close();
93187

94188
return response.fullContext;

0 commit comments

Comments
 (0)