Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
agentchat
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李伟@五瓣科技
agentchat
Commits
786b69d4
Commit
786b69d4
authored
Jun 02, 2025
by
Wade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update grap param
parent
ddcc501a
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
266 additions
and
107 deletions
+266
-107
README.md
README.md
+9
-0
main.go
main.go
+27
-1
graph.go
plugins/graphrag/graph.go
+230
-106
No files found.
README.md
View file @
786b69d4
...
@@ -19,3 +19,12 @@ curl -X POST http://localhost:8000/indexDocuments \
...
@@ -19,3 +19,12 @@ curl -X POST http://localhost:8000/indexDocuments \
curl -X POST http://localhost:8000/indexGraph
\
-H "Content-Type: application/json"
\
-d '{"user_id": "user456", "username": "Bob", "content": "What is the capital of UK?", "metadata": {}}'
{"result": "Document indexed successfully"}
main.go
View file @
786b69d4
...
@@ -33,6 +33,16 @@ type Input struct {
...
@@ -33,6 +33,16 @@ type Input struct {
// DocumentInput 结构体用于文档索引接口
// DocumentInput 结构体用于文档索引接口
type
DocumentInput
struct
{
type
DocumentInput
struct
{
// UserID string `json:"user_id"`
// Username string `json:"username"`
Content
string
`json:"content"`
Metadata
map
[
string
]
interface
{}
`json:"metadata,omitempty"`
}
// GraphInput 结构体用于文档索引接口
type
GraphInput
struct
{
UserID
string
`json:"user_id"`
Username
string
`json:"username"`
Content
string
`json:"content"`
Content
string
`json:"content"`
Metadata
map
[
string
]
interface
{}
`json:"metadata,omitempty"`
Metadata
map
[
string
]
interface
{}
`json:"metadata,omitempty"`
}
}
...
@@ -113,10 +123,26 @@ func main() {
...
@@ -113,10 +123,26 @@ func main() {
_
=
graphRetriever
_
=
graphRetriever
genkit
.
DefineFlow
(
g
,
"indexGraph"
,
func
(
ctx
context
.
Context
,
input
*
DocumentInput
)
(
string
,
error
)
{
genkit
.
DefineFlow
(
g
,
"indexGraph"
,
func
(
ctx
context
.
Context
,
input
*
GraphInput
)
(
string
,
error
)
{
opt
:=
graphrag
.
IndexReqOption
{
UserId
:
input
.
UserID
,
UserName
:
input
.
Username
,
}
if
_
,
ok
:=
input
.
Metadata
[
graphrag
.
DocNameKey
];
!
ok
{
// Generate random docName.
docName
,
err
:=
graphrag
.
GenerateRandomDocName
(
8
)
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"generate random docName for document %w"
,
err
)
}
input
.
Metadata
[
graphrag
.
DocNameKey
]
=
docName
}
doc
:=
ai
.
DocumentFromText
(
input
.
Content
,
input
.
Metadata
)
doc
:=
ai
.
DocumentFromText
(
input
.
Content
,
input
.
Metadata
)
err
:=
graphIndexer
.
Index
(
ctx
,
&
ai
.
IndexerRequest
{
err
:=
graphIndexer
.
Index
(
ctx
,
&
ai
.
IndexerRequest
{
Documents
:
[]
*
ai
.
Document
{
doc
},
Documents
:
[]
*
ai
.
Document
{
doc
},
Options
:
&
opt
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"index document: %w"
,
err
)
return
""
,
fmt
.
Errorf
(
"index document: %w"
,
err
)
...
...
plugins/graphrag/graph.go
View file @
786b69d4
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment