# Ask Knowledge Graph — Writer

> Ask a natural-language question grounded in one or more of your Writer Knowledge Graphs (RAG). Returns an answer with its sources. Use List Knowledge Graphs first to resolve the graph id(s) you want to query. For free-form generation not…

- Key: `writer-ask-knowledge-graph`
- Type: Action (Read-only)
- Version: 0.0.2
- App: Writer (`writer`) — https://pipedream.com/apps/writer.md
- This page (HTML): https://pipedream.com/apps/writer/actions/ask-knowledge-graph
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/writer/actions/ask-knowledge-graph/ask-knowledge-graph.mjs

## Description

Ask a natural-language question grounded in one or more of your Writer Knowledge Graphs (RAG). Returns an answer with its sources. Use **List Knowledge Graphs** first to resolve the graph `id`(s) you want to query. For free-form generation not grounded in your documents, use **Send Prompt** instead. Example: call with `graphIds=["a1b2..."]` and `question="What are the park hours?"` -> returns `{ question, answer, sources, references }`. If a graph has no relevant content it returns a graceful 'no relevant information' answer rather than an error. [See the documentation](https://dev.writer.com/api-reference/kg-api/question)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `graphIds` | `string[]` | Yes | One or more Knowledge Graph UUIDs to query (at least one). Resolve ids with List Knowledge Graphs. |
| `question` | `string` | Yes | The natural-language question to answer from the selected Knowledge Graph(s). Example: What are the park hours? |
| `subqueries` | `boolean` | No | Whether to break the question into subqueries for a more thorough search. Defaults to false. |
| `queryConfig` | `object` | No | Advanced configuration for the Knowledge Graph query, controlling search behavior, grounding, and citations. All keys are optional — supply only the ones you want to override. Supported keys: max_subquestions (integer, 1-10, default 6) — max subquestions generated for complex queries. Higher = more detail, lower = faster. search_weight (integer, 0-100, default 50) — ranking weight; higher (→100) favors keyword matching, lower (→0) favors semantic similarity. grounding_level (number, 0.0-1.0, default 0) — how closely answers stick to source material; higher (→1.0) allows more creative interpretation, lower (→0.0) stays grounded. max_snippets (integer, 1-60, default 30) — max context snippets retrieved. Values below 5 may return no results; recommended range 5-25. max_tokens (integer, 100-8000, default 4000) — max tokens in the generated answer. Higher = longer answers, lower = shorter/faster. keyword_threshold (number, 0.0-1.0, default 0.7) — keyword-match strictness; higher (→1.0) requires stronger keyword matches. semantic_threshold (number, 0.0-1.0, default 0.7) — semantic-similarity strictness; higher (→1.0) requires stronger similarity. inline_citations (boolean, default false) — include inline citations in the response showing which sources were used. Example: { "max_subquestions": 4, "grounding_level": 0.2, "inline_citations": true }. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "writer",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "writer-ask-knowledge-graph",
  arguments: {
    graphIds: ["Graph IDs"],
    question: "Question",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "writer-ask-knowledge-graph",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    writer: { authProvisionId: "apn_xxxxxxx" },
    graphIds: ["Graph IDs"],
    question: "Question",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "writer-ask-knowledge-graph",
    "configured_props": {
      "writer": { "authProvisionId": "apn_xxxxxxx" },
      "graphIds": ["Graph IDs"],
      "question": "Question"
    }
  }'
```

---

- App: https://pipedream.com/apps/writer.md · All apps: https://pipedream.com/apps
