@@ -6,7 +6,11 @@ import {
6
6
State ,
7
7
} from "@ai16z/eliza" ;
8
8
import { createGraphRAG } from "./driver" ;
9
- import { GraphRAGResponse } from "./types" ;
9
+ import {
10
+ GraphRAGResponse ,
11
+ DocumentRelationType ,
12
+ NodeProperties ,
13
+ } from "./types" ;
10
14
import NodeCache from "node-cache" ;
11
15
import * as path from "path" ;
12
16
@@ -68,6 +72,96 @@ export class RAGGraphProvider {
68
72
async close ( ) : Promise < void > {
69
73
await this . graphRAG . close ( ) ;
70
74
}
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
+ }
71
165
}
72
166
73
167
const ragGraphProvider : Provider = {
@@ -88,7 +182,7 @@ const ragGraphProvider: Provider = {
88
182
runtime . cacheManager
89
183
) ;
90
184
91
- const response = await provider . query ( message . content ) ;
185
+ const response = await provider . query ( message . content . text ) ;
92
186
await provider . close ( ) ;
93
187
94
188
return response . fullContext ;
0 commit comments