@jcode.labs/ragmir 6.5.1 → 6.6.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/README.md CHANGED
@@ -73,7 +73,11 @@ budget, with named scopes), `ragmir_expand`, `ragmir_status`, and `ragmir_audit`
73
73
  already returned in a session come back as one-line stubs. Its instructions name the base it
74
74
  serves, and it warns or refuses agents working in unrelated projects. See
75
75
  [agent integration](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/agent-integration.md)
76
- for connection steps and local or self-hosted model examples.
76
+ for connection steps and local or self-hosted model examples. Python agents built with the MCP
77
+ SDK, LangChain, or LlamaIndex use the same server
78
+ ([Python guide](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/python.md)), and
79
+ `ghcr.io/jcode-works/ragmir` runs it without Node.js. LangChain.js chains use `RagmirRetriever`
80
+ from `@jcode.labs/ragmir/langchain` with the optional peer `@langchain/core`.
77
81
 
78
82
  ## TypeScript API
79
83
 
@@ -168,6 +172,7 @@ Never commit private corpus files, .ragmir state, models, or secrets. Treat retr
168
172
  Read the [full documentation](https://github.com/jcode-works/jcode-ragmir#readme),
169
173
  [CLI reference](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/cli-reference.md),
170
174
  [server guide](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/server-deployment.md),
175
+ [Python guide](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/python.md),
171
176
  [migration guide](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/migration.md), and
172
177
  [troubleshooting guide](https://github.com/jcode-works/jcode-ragmir/blob/main/docs/troubleshooting.md).
173
178
  Ask questions and report bugs in
@@ -0,0 +1,60 @@
1
+ import { Document } from "@langchain/core/documents";
2
+ import { BaseRetriever, type BaseRetrieverInput } from "@langchain/core/retrievers";
3
+ import { RagmirClient } from "./client.js";
4
+ import type { SearchOptions, SearchResult, SourceStatus } from "./types.js";
5
+ /** Search settings the retriever forwards to `RagmirClient.search` on every query. */
6
+ export type RagmirRetrieverSearchOptions = Omit<SearchOptions, "cwd" | "explain" | "signal">;
7
+ export interface RagmirRetrieverInput extends BaseRetrieverInput, RagmirRetrieverSearchOptions {
8
+ /**
9
+ * Client to query. The retriever never closes a client it did not open, so one client can serve
10
+ * several retrievers and the rest of the application.
11
+ */
12
+ client?: RagmirClient;
13
+ /**
14
+ * Project root, or a directory inside it, used to open a client on the first query when `client`
15
+ * is not given. Defaults to the current working directory. Call `close()` during shutdown.
16
+ */
17
+ projectRoot?: string;
18
+ }
19
+ /** Citation fields attached to every LangChain document the retriever returns. */
20
+ export interface RagmirDocumentMetadata extends Record<string, unknown> {
21
+ /** Project-relative path of the cited file. */
22
+ source: string;
23
+ /** Exact citation, such as `docs/runbook.md:L12-L18` or a PDF page, slide, or cell range. */
24
+ citation: string;
25
+ chunkIndex: number;
26
+ /** Heading or structural path of the passage inside its file. */
27
+ contextPath: string;
28
+ lineStart: number | null;
29
+ lineEnd: number | null;
30
+ pageStart: number | null;
31
+ pageEnd: number | null;
32
+ /** Vector distance when a semantic model scored the passage, otherwise null. */
33
+ distance: number | null;
34
+ /** The passage holds few of the question's distinctive words: verify it before relying on it. */
35
+ weakEvidence: boolean;
36
+ /** Set when the cited file changed or disappeared since it was indexed. */
37
+ sourceStatus?: SourceStatus;
38
+ knowledgeBaseId?: string;
39
+ }
40
+ /**
41
+ * LangChain.js retriever backed by a local Ragmir base. Each document carries its citation in
42
+ * `metadata`, and a query the indexed sources cannot answer returns an empty list instead of the
43
+ * least unrelated passages.
44
+ */
45
+ export declare class RagmirRetriever extends BaseRetriever<RagmirDocumentMetadata> {
46
+ static lc_name(): string;
47
+ lc_namespace: string[];
48
+ private readonly sharedClient;
49
+ private readonly projectRoot;
50
+ private readonly searchOptions;
51
+ private ownedClient;
52
+ constructor(input?: RagmirRetrieverInput);
53
+ _getRelevantDocuments(query: string): Promise<Document<RagmirDocumentMetadata>[]>;
54
+ /** Closes the client this retriever opened. A client passed in `client` stays open. */
55
+ close(): Promise<void>;
56
+ private client;
57
+ }
58
+ /** Converts one Ragmir search result into a LangChain document that keeps its citation. */
59
+ export declare function ragmirResultToDocument(result: SearchResult): Document<RagmirDocumentMetadata>;
60
+ //# sourceMappingURL=langchain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"langchain.d.ts","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE3E,sFAAsF;AACtF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAA;AAE5F,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB,EAAE,4BAA4B;IAC5F;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,kFAAkF;AAClF,MAAM,WAAW,sBAAuB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrE,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAA;IACd,6FAA6F;IAC7F,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,gFAAgF;IAChF,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,iGAAiG;IACjG,YAAY,EAAE,OAAO,CAAA;IACrB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,aAAa,CAAC,sBAAsB,CAAC;IACxE,MAAM,CAAC,OAAO,IAAI,MAAM,CAEvB;IAED,YAAY,WAA2B;IAEvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA0B;IACvD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA8B;IAC5D,OAAO,CAAC,WAAW,CAAmC;IAEtD,YAAY,KAAK,GAAE,oBAAyB,EAW3C;IAEK,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAItF;IAED,uFAAuF;IACjF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAO3B;IAED,OAAO,CAAC,MAAM;CAiBf;AAED,2FAA2F;AAC3F,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,QAAQ,CAAC,sBAAsB,CAAC,CAwB7F"}
@@ -0,0 +1,86 @@
1
+ import { Document } from "@langchain/core/documents";
2
+ import { BaseRetriever } from "@langchain/core/retrievers";
3
+ import { RagmirClient } from "./client.js";
4
+ /**
5
+ * LangChain.js retriever backed by a local Ragmir base. Each document carries its citation in
6
+ * `metadata`, and a query the indexed sources cannot answer returns an empty list instead of the
7
+ * least unrelated passages.
8
+ */
9
+ export class RagmirRetriever extends BaseRetriever {
10
+ static lc_name() {
11
+ return "RagmirRetriever";
12
+ }
13
+ lc_namespace = ["ragmir", "retrievers"];
14
+ sharedClient;
15
+ projectRoot;
16
+ searchOptions;
17
+ ownedClient;
18
+ constructor(input = {}) {
19
+ const { client, projectRoot, callbacks, tags, metadata, verbose, ...searchOptions } = input;
20
+ super({
21
+ ...(callbacks === undefined ? {} : { callbacks }),
22
+ ...(tags === undefined ? {} : { tags }),
23
+ ...(metadata === undefined ? {} : { metadata }),
24
+ ...(verbose === undefined ? {} : { verbose }),
25
+ });
26
+ this.sharedClient = client;
27
+ this.projectRoot = projectRoot;
28
+ this.searchOptions = searchOptions;
29
+ }
30
+ async _getRelevantDocuments(query) {
31
+ const client = await this.client();
32
+ const results = await client.search(query, this.searchOptions);
33
+ return results.map(ragmirResultToDocument);
34
+ }
35
+ /** Closes the client this retriever opened. A client passed in `client` stays open. */
36
+ async close() {
37
+ const owned = this.ownedClient;
38
+ if (!owned) {
39
+ return;
40
+ }
41
+ const client = await owned.catch(() => undefined);
42
+ await client?.close();
43
+ }
44
+ client() {
45
+ if (this.sharedClient) {
46
+ return Promise.resolve(this.sharedClient);
47
+ }
48
+ if (!this.ownedClient) {
49
+ const opening = RagmirClient.create(this.projectRoot === undefined ? {} : { cwd: this.projectRoot });
50
+ this.ownedClient = opening;
51
+ opening.catch(() => {
52
+ if (this.ownedClient === opening) {
53
+ this.ownedClient = undefined;
54
+ }
55
+ });
56
+ }
57
+ return this.ownedClient;
58
+ }
59
+ }
60
+ /** Converts one Ragmir search result into a LangChain document that keeps its citation. */
61
+ export function ragmirResultToDocument(result) {
62
+ const metadata = {
63
+ source: result.relativePath,
64
+ citation: result.citation,
65
+ chunkIndex: result.chunkIndex,
66
+ contextPath: result.contextPath,
67
+ lineStart: result.lineStart,
68
+ lineEnd: result.lineEnd,
69
+ pageStart: result.pageStart,
70
+ pageEnd: result.pageEnd,
71
+ distance: result.distance,
72
+ weakEvidence: result.weakEvidence === true,
73
+ };
74
+ if (result.sourceStatus) {
75
+ metadata.sourceStatus = result.sourceStatus;
76
+ }
77
+ if (result.evidence?.knowledgeBaseId) {
78
+ metadata.knowledgeBaseId = result.evidence.knowledgeBaseId;
79
+ }
80
+ return new Document({
81
+ pageContent: result.text,
82
+ metadata,
83
+ id: result.evidence?.id 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;IACzB,CAAC;CACF;AAED,2FAA2F;AAC3F,MAAM,UAAU,sBAAsB,CAAC,MAAoB;IACzD,MAAM,QAAQ,GAA2B;QACvC,MAAM,EAAE,MAAM,CAAC,YAAY;QAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY,KAAK,IAAI;KAC3C,CAAA;IACD,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QACxB,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAA;IAC7C,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAC;QACrC,QAAQ,CAAC,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAA;IAC5D,CAAC;IACD,OAAO,IAAI,QAAQ,CAAyB;QAC1C,WAAW,EAAE,MAAM,CAAC,IAAI;QACxB,QAAQ;QACR,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,MAAM,CAAC,QAAQ;KAC3C,CAAC,CAAA;AACJ,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "6.5.1";
1
+ export declare const VERSION = "6.6.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = "6.5.1";
1
+ export const VERSION = "6.6.0";
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@jcode.labs/ragmir",
3
- "version": "6.5.1",
3
+ "mcpName": "io.github.jcode-works/ragmir",
4
+ "version": "6.6.0",
4
5
  "description": "Open-source retrieval for agentic RAG: document search with exact citations on your laptop or servers, with OCR, CLI, MCP, and TypeScript.",
5
6
  "type": "module",
6
7
  "license": "AGPL-3.0-only",
@@ -48,6 +49,10 @@
48
49
  ".": {
49
50
  "types": "./dist/index.d.ts",
50
51
  "import": "./dist/index.js"
52
+ },
53
+ "./langchain": {
54
+ "types": "./dist/langchain.d.ts",
55
+ "import": "./dist/langchain.js"
51
56
  }
52
57
  },
53
58
  "bin": {
@@ -81,11 +86,15 @@
81
86
  "zod": "^4.6.7"
82
87
  },
83
88
  "peerDependencies": {
84
- "@huggingface/transformers": "^4.3.0"
89
+ "@huggingface/transformers": "^4.3.0",
90
+ "@langchain/core": "^1.0.0"
85
91
  },
86
92
  "peerDependenciesMeta": {
87
93
  "@huggingface/transformers": {
88
94
  "optional": true
95
+ },
96
+ "@langchain/core": {
97
+ "optional": true
89
98
  }
90
99
  },
91
100
  "devDependencies": {