rag-memory-pg-mcp 2.1.0 โ 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -2
- package/README.md +9 -5
- package/package.json +1 -1
- package/src/handlers.js +2 -1
- package/src/index.js +71 -3
- package/src/prompts.js +78 -0
- package/src/tool-modes.js +1 -1
- package/src/tools.js +111 -34
- package/test-openai-embeddings.js +0 -81
package/CHANGELOG.md
CHANGED
|
@@ -5,12 +5,47 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.2.0] - 2026-01-05
|
|
9
|
+
|
|
10
|
+
### Breaking Changes ๐ด
|
|
11
|
+
- **Renamed `readGraph` โ `getGraph`** due to Cursor API conflict
|
|
12
|
+
- The `readGraph` name was causing the tool to be ignored/blocked by Cursor
|
|
13
|
+
- Handler supports both names for backward compatibility
|
|
14
|
+
|
|
15
|
+
### Fixed ๐
|
|
16
|
+
- **Tool loading in CLIENT mode** - now correctly shows 10 tools (was showing 9)
|
|
17
|
+
- Root cause: `readGraph` conflicted with Cursor internal API
|
|
18
|
+
- Solution: Renamed to `getGraph` - all tools now load properly
|
|
19
|
+
|
|
20
|
+
### Technical Details
|
|
21
|
+
- Debug analysis showed server was sending 10 tools correctly
|
|
22
|
+
- Cursor was blocking/ignoring the `readGraph` tool during registration
|
|
23
|
+
- Tool name conflict resolved by renaming
|
|
24
|
+
|
|
25
|
+
## [2.1.1] - 2026-01-05
|
|
26
|
+
|
|
27
|
+
### Added โจ
|
|
28
|
+
- **Server instructions** for AI models with key principles and workflows
|
|
29
|
+
- **Pre-defined prompts** (store-knowledge, search-knowledge, explore-graph)
|
|
30
|
+
- **Enhanced tool descriptions** following MCP best practices
|
|
31
|
+
- Prominent **English language requirement** warnings throughout
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- All tool descriptions now include examples and use cases
|
|
35
|
+
- Parameter descriptions are more detailed and actionable
|
|
36
|
+
- Better guidance for AI models on tool selection
|
|
37
|
+
|
|
38
|
+
### Documentation
|
|
39
|
+
- Added language requirement warnings in README
|
|
40
|
+
- Server metadata includes comprehensive instructions
|
|
41
|
+
- Prompts provide guided workflows for common tasks
|
|
42
|
+
|
|
8
43
|
## [2.1.0] - 2026-01-05
|
|
9
44
|
|
|
10
45
|
### Added โจ
|
|
11
46
|
- **TOOLS_MODE environment variable** for flexible tool sets
|
|
12
|
-
- `TOOLS_MODE=client` -
|
|
13
|
-
- `TOOLS_MODE=maintenance` -
|
|
47
|
+
- `TOOLS_MODE=client` - 10 essential tools for daily memory operations (recommended)
|
|
48
|
+
- `TOOLS_MODE=maintenance` - 11 admin/cleanup tools for database management
|
|
14
49
|
- `TOOLS_MODE=full` - All 21 tools (default)
|
|
15
50
|
- Automatic updates via `@latest` in all npx commands
|
|
16
51
|
- UPDATE_GUIDE.md with update instructions
|
package/README.md
CHANGED
|
@@ -154,6 +154,8 @@ Then restart Windsurf.
|
|
|
154
154
|
- **Hybrid Search**: Combines text and semantic search
|
|
155
155
|
- **Multi-Machine Sync**: PostgreSQL backend enables real-time sync across devices
|
|
156
156
|
|
|
157
|
+
> **โ ๏ธ Important:** All content (entities, documents, queries) should be stored and searched in **English** for optimal embedding and search performance. The embedding models are trained on English text and work best with English input.
|
|
158
|
+
|
|
157
159
|
## ๐ฆ Installation Options
|
|
158
160
|
|
|
159
161
|
### Option 1: Direct via npx (Recommended)
|
|
@@ -184,19 +186,19 @@ npm install -g github:kshidenko/rag-memory-pg-mcp
|
|
|
184
186
|
### Tools Mode
|
|
185
187
|
|
|
186
188
|
- **`full`** (default) - All 21 tools for complete functionality
|
|
187
|
-
- **`client`** -
|
|
188
|
-
- **`maintenance`** -
|
|
189
|
+
- **`client`** - 10 essential tools for daily memory operations (recommended for most users)
|
|
190
|
+
- **`maintenance`** - 11 admin/cleanup tools for database management
|
|
189
191
|
|
|
190
192
|
<details>
|
|
191
193
|
<summary><b>Tools by Mode</b></summary>
|
|
192
194
|
|
|
193
|
-
**CLIENT mode (
|
|
195
|
+
**CLIENT mode (10 tools) - Recommended for daily use:**
|
|
194
196
|
- Knowledge Graph: createEntities, createRelations, addObservations, searchNodes, openNodes
|
|
195
197
|
- Documents: processDocument (โญ main tool)
|
|
196
198
|
- Search: hybridSearch, getDetailedContext
|
|
197
|
-
- Info:
|
|
199
|
+
- Info: getGraph, getKnowledgeGraphStats
|
|
198
200
|
|
|
199
|
-
**MAINTENANCE mode (
|
|
201
|
+
**MAINTENANCE mode (11 tools) - For cleanup and admin:**
|
|
200
202
|
- Cleanup: deleteEntities, deleteRelations, deleteObservations, deleteDocuments
|
|
201
203
|
- Advanced: storeDocument, chunkDocument, embedChunks, embedAllEntities
|
|
202
204
|
- Utilities: listDocuments, extractTerms, linkEntitiesToDocument
|
|
@@ -208,6 +210,8 @@ npm install -g github:kshidenko/rag-memory-pg-mcp
|
|
|
208
210
|
|
|
209
211
|
## Available Tools (21 total)
|
|
210
212
|
|
|
213
|
+
> **Language Note:** All tools expect English input for entity names, observations, document content, and search queries. This ensures optimal embedding quality and search accuracy.
|
|
214
|
+
|
|
211
215
|
### Document Processing
|
|
212
216
|
|
|
213
217
|
#### `processDocument` โญ Recommended
|
package/package.json
CHANGED
package/src/handlers.js
CHANGED
|
@@ -102,7 +102,8 @@ async function executeToolMethod(name, args, manager) {
|
|
|
102
102
|
includeEntities: args.includeEntities,
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
case '
|
|
105
|
+
case 'getGraph':
|
|
106
|
+
case 'readGraph': // Backward compatibility
|
|
106
107
|
return manager.readGraph();
|
|
107
108
|
|
|
108
109
|
// ==================== UTILITIES ====================
|
package/src/index.js
CHANGED
|
@@ -20,11 +20,14 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
20
20
|
import {
|
|
21
21
|
CallToolRequestSchema,
|
|
22
22
|
ListToolsRequestSchema,
|
|
23
|
+
ListPromptsRequestSchema,
|
|
24
|
+
GetPromptRequestSchema,
|
|
23
25
|
} from '@modelcontextprotocol/sdk/types.js';
|
|
24
26
|
|
|
25
27
|
import { RAGKnowledgeGraphManager } from './manager.js';
|
|
26
28
|
import { getToolDefinitions } from './tools.js';
|
|
27
29
|
import { filterToolsByMode } from './tool-modes.js';
|
|
30
|
+
import { getPromptDefinitions } from './prompts.js';
|
|
28
31
|
import { handleToolCall, createErrorResponse } from './handlers.js';
|
|
29
32
|
|
|
30
33
|
// ==================== CONFIGURATION ====================
|
|
@@ -41,8 +44,8 @@ if (!SUPABASE_URL || !SUPABASE_KEY) {
|
|
|
41
44
|
|
|
42
45
|
// Log active tools mode
|
|
43
46
|
const modeDescriptions = {
|
|
44
|
-
client: 'CLIENT mode (
|
|
45
|
-
maintenance: 'MAINTENANCE mode (
|
|
47
|
+
client: 'CLIENT mode (10 essential tools for daily use)',
|
|
48
|
+
maintenance: 'MAINTENANCE mode (11 admin/cleanup tools)',
|
|
46
49
|
full: 'FULL mode (all 21 tools)'
|
|
47
50
|
};
|
|
48
51
|
console.error(`๐ง Tools: ${modeDescriptions[TOOLS_MODE] || 'FULL mode (default)'}`);
|
|
@@ -59,11 +62,36 @@ console.error(`๐ Active tools: ${activeTools.length}/${allTools.length}`);
|
|
|
59
62
|
const server = new Server(
|
|
60
63
|
{
|
|
61
64
|
name: 'rag-memory-pg',
|
|
62
|
-
version: '2.
|
|
65
|
+
version: '2.2.0',
|
|
66
|
+
description: 'RAG-enabled memory with PostgreSQL/Supabase backend. Provides knowledge graph, document management, and semantic search. All content should be in English for optimal performance.',
|
|
67
|
+
instructions: `This is a RAG (Retrieval-Augmented Generation) memory system with knowledge graph capabilities.
|
|
68
|
+
|
|
69
|
+
KEY PRINCIPLES:
|
|
70
|
+
1. ALL content (entities, documents, queries) must be in ENGLISH for optimal embedding and search
|
|
71
|
+
2. Use processDocument for storing documentation/code examples
|
|
72
|
+
3. Use createEntities + createRelations for structured knowledge
|
|
73
|
+
4. Use hybridSearch or getDetailedContext for finding information
|
|
74
|
+
|
|
75
|
+
RECOMMENDED WORKFLOW:
|
|
76
|
+
- Store knowledge: processDocument (documents) + createEntities (concepts) + createRelations (links)
|
|
77
|
+
- Search knowledge: hybridSearch (documents) or searchNodes (entities)
|
|
78
|
+
- Explore: readGraph (full overview) or getKnowledgeGraphStats (statistics)
|
|
79
|
+
|
|
80
|
+
TOOL MODES:
|
|
81
|
+
- client: 10 essential tools for daily use (recommended)
|
|
82
|
+
- maintenance: 11 admin/cleanup tools
|
|
83
|
+
- full: all 21 tools (default)
|
|
84
|
+
|
|
85
|
+
EMBEDDING MODES:
|
|
86
|
+
- local: Free, private, slower (default)
|
|
87
|
+
- openai: 10-100x faster, cloud-based (recommended)
|
|
88
|
+
|
|
89
|
+
Use English for all operations to ensure accurate semantic search and embedding quality.`,
|
|
63
90
|
},
|
|
64
91
|
{
|
|
65
92
|
capabilities: {
|
|
66
93
|
tools: {},
|
|
94
|
+
prompts: {},
|
|
67
95
|
},
|
|
68
96
|
}
|
|
69
97
|
);
|
|
@@ -79,6 +107,46 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
79
107
|
return { tools: activeTools };
|
|
80
108
|
});
|
|
81
109
|
|
|
110
|
+
/**
|
|
111
|
+
* List available prompts
|
|
112
|
+
*/
|
|
113
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
114
|
+
return { prompts: getPromptDefinitions() };
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get specific prompt
|
|
119
|
+
*/
|
|
120
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
121
|
+
const prompts = getPromptDefinitions();
|
|
122
|
+
const prompt = prompts.find(p => p.name === request.params.name);
|
|
123
|
+
|
|
124
|
+
if (!prompt) {
|
|
125
|
+
throw new Error(`Prompt not found: ${request.params.name}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Replace template variables
|
|
129
|
+
let messages = [{
|
|
130
|
+
role: 'user',
|
|
131
|
+
content: {
|
|
132
|
+
type: 'text',
|
|
133
|
+
text: prompt.prompt,
|
|
134
|
+
},
|
|
135
|
+
}];
|
|
136
|
+
|
|
137
|
+
// Replace {{variable}} in prompt with actual arguments
|
|
138
|
+
if (request.params.arguments) {
|
|
139
|
+
Object.entries(request.params.arguments).forEach(([key, value]) => {
|
|
140
|
+
messages[0].content.text = messages[0].content.text.replace(
|
|
141
|
+
new RegExp(`{{${key}}}`, 'g'),
|
|
142
|
+
value
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { messages };
|
|
148
|
+
});
|
|
149
|
+
|
|
82
150
|
/**
|
|
83
151
|
* Handle tool calls
|
|
84
152
|
*/
|
package/src/prompts.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Prompts
|
|
3
|
+
*
|
|
4
|
+
* Pre-defined prompts that help users and AI models understand how to use the RAG Memory system effectively.
|
|
5
|
+
*
|
|
6
|
+
* @module prompts
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export function getPromptDefinitions() {
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
name: 'store-knowledge',
|
|
13
|
+
description: 'Store new knowledge (documentation, code examples, or concepts) in RAG memory',
|
|
14
|
+
arguments: [
|
|
15
|
+
{
|
|
16
|
+
name: 'topic',
|
|
17
|
+
description: 'Topic or subject of the knowledge (e.g., "Next.js routing", "PostgreSQL optimization")',
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'content',
|
|
22
|
+
description: 'The actual content/documentation to store',
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
prompt: `I'll help you store knowledge about {{topic}} in the RAG memory system.
|
|
27
|
+
|
|
28
|
+
**Best Practices:**
|
|
29
|
+
1. All content must be in English for optimal search performance
|
|
30
|
+
2. Use clear, descriptive entity names
|
|
31
|
+
3. Add comprehensive observations with specific details
|
|
32
|
+
4. Create relationships between related concepts
|
|
33
|
+
|
|
34
|
+
**Steps:**
|
|
35
|
+
1. Create entities for main concepts
|
|
36
|
+
2. Add detailed observations
|
|
37
|
+
3. Create relationships to connect knowledge
|
|
38
|
+
4. Store full documentation using processDocument
|
|
39
|
+
|
|
40
|
+
Let me process "{{content}}" and create a comprehensive knowledge graph entry.`,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'search-knowledge',
|
|
44
|
+
description: 'Search for information in the RAG memory using hybrid semantic search',
|
|
45
|
+
arguments: [
|
|
46
|
+
{
|
|
47
|
+
name: 'query',
|
|
48
|
+
description: 'What are you looking for? (in English)',
|
|
49
|
+
required: true,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
prompt: `I'll search the RAG memory for information about "{{query}}".
|
|
53
|
+
|
|
54
|
+
**Search Strategy:**
|
|
55
|
+
1. Using hybridSearch for semantic + text matching
|
|
56
|
+
2. Query in English for best embedding results
|
|
57
|
+
3. Retrieving top relevant document chunks
|
|
58
|
+
4. Including related entities from knowledge graph
|
|
59
|
+
|
|
60
|
+
Searching now...`,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'explore-graph',
|
|
64
|
+
description: 'Explore the knowledge graph to see what information is stored',
|
|
65
|
+
arguments: [],
|
|
66
|
+
prompt: `I'll show you the complete knowledge graph structure.
|
|
67
|
+
|
|
68
|
+
**What you'll see:**
|
|
69
|
+
- All entities (people, projects, technologies, concepts)
|
|
70
|
+
- Relationships between entities
|
|
71
|
+
- Total counts and statistics
|
|
72
|
+
|
|
73
|
+
This gives you a bird's-eye view of all stored knowledge.
|
|
74
|
+
|
|
75
|
+
Reading graph now...`,
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
package/src/tool-modes.js
CHANGED
|
@@ -27,7 +27,7 @@ export const TOOL_MODES = {
|
|
|
27
27
|
'getDetailedContext', // Get rich context with entities
|
|
28
28
|
|
|
29
29
|
// Utilities - Basic info
|
|
30
|
-
'
|
|
30
|
+
'getGraph', // View knowledge graph (renamed from readGraph)
|
|
31
31
|
'getKnowledgeGraphStats', // See statistics
|
|
32
32
|
],
|
|
33
33
|
|
package/src/tools.js
CHANGED
|
@@ -13,22 +13,33 @@
|
|
|
13
13
|
* @returns {object[]} Array of tool definitions
|
|
14
14
|
*/
|
|
15
15
|
export function getToolDefinitions() {
|
|
16
|
-
|
|
16
|
+
const tools = [
|
|
17
17
|
// ==================== ENTITY TOOLS ====================
|
|
18
18
|
{
|
|
19
19
|
name: 'createEntities',
|
|
20
|
-
description: 'Create new entities in the knowledge graph',
|
|
20
|
+
description: 'Create new entities in the knowledge graph. Use this to store structured information about people, projects, technologies, concepts, or any important items. Entity names and observations should be in English for consistency.',
|
|
21
21
|
inputSchema: {
|
|
22
22
|
type: 'object',
|
|
23
23
|
properties: {
|
|
24
24
|
entities: {
|
|
25
25
|
type: 'array',
|
|
26
|
+
description: 'Array of entities to create',
|
|
26
27
|
items: {
|
|
27
28
|
type: 'object',
|
|
28
29
|
properties: {
|
|
29
|
-
name: {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
name: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'Unique entity name in English. Examples: "React", "John Doe", "NextJS Project"'
|
|
33
|
+
},
|
|
34
|
+
entityType: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
description: 'Entity category in English. Examples: "TECHNOLOGY", "PERSON", "PROJECT", "CONCEPT"'
|
|
37
|
+
},
|
|
38
|
+
observations: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
items: { type: 'string' },
|
|
41
|
+
description: 'Facts and observations about this entity in English. Examples: ["JavaScript library", "Created by Facebook", "Used for UI development"]'
|
|
42
|
+
},
|
|
32
43
|
},
|
|
33
44
|
required: ['name', 'entityType', 'observations'],
|
|
34
45
|
},
|
|
@@ -39,18 +50,28 @@ export function getToolDefinitions() {
|
|
|
39
50
|
},
|
|
40
51
|
{
|
|
41
52
|
name: 'createRelations',
|
|
42
|
-
description: 'Create relationships between entities',
|
|
53
|
+
description: 'Create relationships between existing entities in the knowledge graph. Use this to connect related concepts, show dependencies, or build knowledge networks. Relationship types should be in English.',
|
|
43
54
|
inputSchema: {
|
|
44
55
|
type: 'object',
|
|
45
56
|
properties: {
|
|
46
57
|
relations: {
|
|
47
58
|
type: 'array',
|
|
59
|
+
description: 'Array of relationships to create between entities',
|
|
48
60
|
items: {
|
|
49
61
|
type: 'object',
|
|
50
62
|
properties: {
|
|
51
|
-
from: {
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
from: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
description: 'Source entity name (must exist). Example: "React"'
|
|
66
|
+
},
|
|
67
|
+
to: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
description: 'Target entity name (must exist). Example: "JavaScript"'
|
|
70
|
+
},
|
|
71
|
+
relationType: {
|
|
72
|
+
type: 'string',
|
|
73
|
+
description: 'Relationship type in English. Examples: "BUILT_WITH", "USES", "DEPENDS_ON", "CREATED_BY", "PART_OF"'
|
|
74
|
+
},
|
|
54
75
|
},
|
|
55
76
|
required: ['from', 'to', 'relationType'],
|
|
56
77
|
},
|
|
@@ -61,17 +82,25 @@ export function getToolDefinitions() {
|
|
|
61
82
|
},
|
|
62
83
|
{
|
|
63
84
|
name: 'addObservations',
|
|
64
|
-
description: 'Add observations to existing entities',
|
|
85
|
+
description: 'Add new observations (facts, notes, details) to existing entities. Use this to enrich entities with additional information over time. All observations should be in English for consistency.',
|
|
65
86
|
inputSchema: {
|
|
66
87
|
type: 'object',
|
|
67
88
|
properties: {
|
|
68
89
|
observations: {
|
|
69
90
|
type: 'array',
|
|
91
|
+
description: 'Array of observations to add to entities',
|
|
70
92
|
items: {
|
|
71
93
|
type: 'object',
|
|
72
94
|
properties: {
|
|
73
|
-
entityName: {
|
|
74
|
-
|
|
95
|
+
entityName: {
|
|
96
|
+
type: 'string',
|
|
97
|
+
description: 'Name of existing entity. Example: "React"'
|
|
98
|
+
},
|
|
99
|
+
contents: {
|
|
100
|
+
type: 'array',
|
|
101
|
+
items: { type: 'string' },
|
|
102
|
+
description: 'Array of new observations in English. Examples: ["Released version 18", "Added concurrent features", "Improved performance"]'
|
|
103
|
+
},
|
|
75
104
|
},
|
|
76
105
|
required: ['entityName', 'contents'],
|
|
77
106
|
},
|
|
@@ -82,23 +111,34 @@ export function getToolDefinitions() {
|
|
|
82
111
|
},
|
|
83
112
|
{
|
|
84
113
|
name: 'searchNodes',
|
|
85
|
-
description: 'Search for entities by name or type',
|
|
114
|
+
description: 'Search for entities in the knowledge graph by name or type. Use English keywords for best results. Returns matching entities with their types and observations.',
|
|
86
115
|
inputSchema: {
|
|
87
116
|
type: 'object',
|
|
88
117
|
properties: {
|
|
89
|
-
query: {
|
|
90
|
-
|
|
118
|
+
query: {
|
|
119
|
+
type: 'string',
|
|
120
|
+
description: 'Search query in English. Can search by entity name or type. Examples: "React", "PERSON", "database"'
|
|
121
|
+
},
|
|
122
|
+
limit: {
|
|
123
|
+
type: 'number',
|
|
124
|
+
default: 10,
|
|
125
|
+
description: 'Maximum number of entities to return (default: 10)'
|
|
126
|
+
},
|
|
91
127
|
},
|
|
92
128
|
required: ['query'],
|
|
93
129
|
},
|
|
94
130
|
},
|
|
95
131
|
{
|
|
96
132
|
name: 'openNodes',
|
|
97
|
-
description: 'Get specific entities by
|
|
133
|
+
description: 'Get complete details of specific entities by their exact names. Returns entity type, all observations, and related connections. Use this to retrieve full information about known entities.',
|
|
98
134
|
inputSchema: {
|
|
99
135
|
type: 'object',
|
|
100
136
|
properties: {
|
|
101
|
-
names: {
|
|
137
|
+
names: {
|
|
138
|
+
type: 'array',
|
|
139
|
+
items: { type: 'string' },
|
|
140
|
+
description: 'Array of exact entity names to retrieve. Examples: ["React", "Next.js", "TypeScript"]'
|
|
141
|
+
},
|
|
102
142
|
},
|
|
103
143
|
required: ['names'],
|
|
104
144
|
},
|
|
@@ -165,15 +205,32 @@ export function getToolDefinitions() {
|
|
|
165
205
|
// ==================== DOCUMENT TOOLS ====================
|
|
166
206
|
{
|
|
167
207
|
name: 'processDocument',
|
|
168
|
-
description: 'RECOMMENDED: Store document with full pipeline (store โ chunk โ embed)',
|
|
208
|
+
description: 'โญ RECOMMENDED: Store document with full pipeline (store โ chunk โ embed). Use this for adding any documentation, code examples, or knowledge. Content should be in English for optimal search performance. Automatically chunks text and generates embeddings.',
|
|
169
209
|
inputSchema: {
|
|
170
210
|
type: 'object',
|
|
171
211
|
properties: {
|
|
172
|
-
id: {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
212
|
+
id: {
|
|
213
|
+
type: 'string',
|
|
214
|
+
description: 'Unique document identifier. Use descriptive names like "nextjs-routing-docs" or "postgres-optimization-guide"'
|
|
215
|
+
},
|
|
216
|
+
content: {
|
|
217
|
+
type: 'string',
|
|
218
|
+
description: 'Document content in English. Can be markdown, code examples, documentation, or any text knowledge'
|
|
219
|
+
},
|
|
220
|
+
maxChunkSize: {
|
|
221
|
+
type: 'number',
|
|
222
|
+
default: 500,
|
|
223
|
+
description: 'Maximum characters per chunk (default: 500). Smaller chunks = more precise search'
|
|
224
|
+
},
|
|
225
|
+
overlap: {
|
|
226
|
+
type: 'number',
|
|
227
|
+
default: 50,
|
|
228
|
+
description: 'Character overlap between chunks (default: 50). Ensures context continuity'
|
|
229
|
+
},
|
|
230
|
+
metadata: {
|
|
231
|
+
type: 'object',
|
|
232
|
+
description: 'Optional metadata like {type: "documentation", source: "official", version: "1.0"}'
|
|
233
|
+
},
|
|
177
234
|
},
|
|
178
235
|
required: ['id', 'content'],
|
|
179
236
|
},
|
|
@@ -240,7 +297,7 @@ export function getToolDefinitions() {
|
|
|
240
297
|
},
|
|
241
298
|
{
|
|
242
299
|
name: 'embedAllEntities',
|
|
243
|
-
description: 'Generate embeddings for all entities',
|
|
300
|
+
description: 'Generate embeddings for all entities in the knowledge graph. Use this to enable semantic search on entities or after adding many new entities. No parameters required.',
|
|
244
301
|
inputSchema: {
|
|
245
302
|
type: 'object',
|
|
246
303
|
properties: {},
|
|
@@ -250,32 +307,50 @@ export function getToolDefinitions() {
|
|
|
250
307
|
// ==================== SEARCH TOOLS ====================
|
|
251
308
|
{
|
|
252
309
|
name: 'hybridSearch',
|
|
253
|
-
description: 'Search documents using hybrid search',
|
|
310
|
+
description: 'Search documents using hybrid semantic + text search. Query must be in English for best results. Returns relevant document chunks with similarity scores.',
|
|
254
311
|
inputSchema: {
|
|
255
312
|
type: 'object',
|
|
256
313
|
properties: {
|
|
257
|
-
query: {
|
|
258
|
-
|
|
314
|
+
query: {
|
|
315
|
+
type: 'string',
|
|
316
|
+
description: 'Search query in English. Examples: "React hooks usage", "authentication patterns", "database optimization"'
|
|
317
|
+
},
|
|
318
|
+
limit: {
|
|
319
|
+
type: 'number',
|
|
320
|
+
default: 5,
|
|
321
|
+
description: 'Maximum number of results to return (default: 5)'
|
|
322
|
+
},
|
|
259
323
|
},
|
|
260
324
|
required: ['query'],
|
|
261
325
|
},
|
|
262
326
|
},
|
|
263
327
|
{
|
|
264
328
|
name: 'getDetailedContext',
|
|
265
|
-
description: 'Get detailed context
|
|
329
|
+
description: 'Get detailed context combining semantic document search with related entities from knowledge graph. Query must be in English. Returns document chunks + connected entities for comprehensive understanding.',
|
|
266
330
|
inputSchema: {
|
|
267
331
|
type: 'object',
|
|
268
332
|
properties: {
|
|
269
|
-
query: {
|
|
270
|
-
|
|
271
|
-
|
|
333
|
+
query: {
|
|
334
|
+
type: 'string',
|
|
335
|
+
description: 'Search query in English. Examples: "Next.js routing", "PostgreSQL optimization", "React state management"'
|
|
336
|
+
},
|
|
337
|
+
limit: {
|
|
338
|
+
type: 'number',
|
|
339
|
+
default: 5,
|
|
340
|
+
description: 'Maximum number of document results (default: 5)'
|
|
341
|
+
},
|
|
342
|
+
includeEntities: {
|
|
343
|
+
type: 'boolean',
|
|
344
|
+
default: true,
|
|
345
|
+
description: 'Include related entities from knowledge graph (default: true)'
|
|
346
|
+
},
|
|
272
347
|
},
|
|
273
348
|
required: ['query'],
|
|
274
349
|
},
|
|
275
350
|
},
|
|
276
351
|
{
|
|
277
|
-
name: '
|
|
278
|
-
description: '
|
|
352
|
+
name: 'getGraph',
|
|
353
|
+
description: 'Get the entire knowledge graph with all entities, relationships, and observations. Use this to retrieve complete overview of stored knowledge. Returns full graph structure for analysis or visualization. No parameters required.',
|
|
279
354
|
inputSchema: {
|
|
280
355
|
type: 'object',
|
|
281
356
|
properties: {},
|
|
@@ -285,7 +360,7 @@ export function getToolDefinitions() {
|
|
|
285
360
|
// ==================== UTILITY TOOLS ====================
|
|
286
361
|
{
|
|
287
362
|
name: 'getKnowledgeGraphStats',
|
|
288
|
-
description: 'Get statistics about the knowledge graph',
|
|
363
|
+
description: 'Get statistics about the knowledge graph including total counts of entities, relationships, documents, and chunks. Use this to understand the size and scope of stored knowledge. Returns entity_count, relationship_count, document_count, chunk_count, and type distributions. No parameters required.',
|
|
289
364
|
inputSchema: {
|
|
290
365
|
type: 'object',
|
|
291
366
|
properties: {},
|
|
@@ -317,4 +392,6 @@ export function getToolDefinitions() {
|
|
|
317
392
|
},
|
|
318
393
|
},
|
|
319
394
|
];
|
|
395
|
+
|
|
396
|
+
return tools;
|
|
320
397
|
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Test script to verify OpenAI embeddings work correctly
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* MODE=openai OPENAI_API_KEY=sk-... node test-openai-embeddings.js
|
|
7
|
-
*
|
|
8
|
-
* Or test local mode:
|
|
9
|
-
* MODE=local node test-openai-embeddings.js
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { RAGKnowledgeGraphManager } from './src/manager.js';
|
|
13
|
-
|
|
14
|
-
async function testOpenAIEmbeddings() {
|
|
15
|
-
console.log('๐งช Testing OpenAI Embeddings Integration...\n');
|
|
16
|
-
|
|
17
|
-
// Check env vars
|
|
18
|
-
const mode = (process.env.MODE || 'local').toLowerCase();
|
|
19
|
-
const hasOpenAIKey = !!process.env.OPENAI_API_KEY;
|
|
20
|
-
|
|
21
|
-
console.log(`๐ Configuration:`);
|
|
22
|
-
console.log(` MODE: ${mode}`);
|
|
23
|
-
console.log(` OPENAI_API_KEY: ${hasOpenAIKey ? 'โ
Set' : 'โ Not set'}`);
|
|
24
|
-
console.log();
|
|
25
|
-
|
|
26
|
-
// Initialize manager
|
|
27
|
-
const manager = new RAGKnowledgeGraphManager(
|
|
28
|
-
process.env.SUPABASE_URL,
|
|
29
|
-
process.env.SUPABASE_SERVICE_KEY
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
await manager.initialize();
|
|
33
|
-
|
|
34
|
-
// Test embedding generation
|
|
35
|
-
console.log('๐ฎ Generating test embedding...');
|
|
36
|
-
const testText = 'This is a test for OpenAI embeddings with 384 dimensions';
|
|
37
|
-
|
|
38
|
-
const startTime = Date.now();
|
|
39
|
-
const embedding = await manager.generateEmbedding(testText);
|
|
40
|
-
const duration = Date.now() - startTime;
|
|
41
|
-
|
|
42
|
-
if (!embedding) {
|
|
43
|
-
console.error('โ Failed to generate embedding');
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
console.log(`โ
Embedding generated in ${duration}ms`);
|
|
48
|
-
console.log(` Dimensions: ${embedding.length}`);
|
|
49
|
-
console.log(` First 5 values: [${embedding.slice(0, 5).map(v => v.toFixed(4)).join(', ')}...]`);
|
|
50
|
-
console.log(` Mode used: ${manager.mode}`);
|
|
51
|
-
|
|
52
|
-
// Verify dimensions
|
|
53
|
-
if (embedding.length !== 384) {
|
|
54
|
-
console.error(`โ Expected 384 dimensions, got ${embedding.length}`);
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Test multiple embeddings for performance
|
|
59
|
-
console.log('\nโก Performance test (5 embeddings)...');
|
|
60
|
-
const perfStart = Date.now();
|
|
61
|
-
|
|
62
|
-
for (let i = 0; i < 5; i++) {
|
|
63
|
-
await manager.generateEmbedding(`Test text ${i}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const avgTime = (Date.now() - perfStart) / 5;
|
|
67
|
-
console.log(` Average time: ${avgTime.toFixed(0)}ms per embedding`);
|
|
68
|
-
|
|
69
|
-
if (mode === 'openai') {
|
|
70
|
-
console.log(` Expected: 50-200ms (OpenAI is fast!)`);
|
|
71
|
-
} else {
|
|
72
|
-
console.log(` Expected: 200-2000ms (Local model)`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
console.log('\nโ
All tests passed!');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
testOpenAIEmbeddings().catch(error => {
|
|
79
|
-
console.error('โ Test failed:', error.message);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
});
|