@o-lang/semantic-doc-search 1.0.7 → 1.0.8

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/bin/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import yargs from "yargs";
3
- import { hideBin } from "yargs/helpers";
4
- import resolver from "../src/index.js";
2
+ const yargs = require("yargs");
3
+ const { hideBin } = require("yargs/helpers");
4
+ const resolver = require("../src/index.js");
5
5
 
6
6
  const argv = yargs(hideBin(process.argv))
7
7
  .usage("Usage: $0 <query> [options]")
@@ -48,44 +48,4 @@ const context = {
48
48
  } catch (err) {
49
49
  console.error("\n❌ Error running search:", err);
50
50
  }
51
- })();
52
-
53
-
54
- // console.error("❌ Please provide a query string.");
55
- // process.exit(1);
56
- // }
57
-
58
- // const stream = argv.stream || false;
59
- // const provider = argv.provider || "openai";
60
-
61
- // // Resolve doc_root if given
62
- // const doc_root = argv.doc_root
63
- // ? path.resolve(__dirname, "..", argv.doc_root)
64
- // : undefined;
65
-
66
- // // Optional runtime API keys (users pass env variables)
67
- // const openaiApiKey = process.env.OPENAI_API_KEY;
68
- // const groqApiKey = process.env.GROQ_API_KEY;
69
- // const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
70
-
71
- // (async () => {
72
- // try {
73
- // const result = await resolver("search", {
74
- // query,
75
- // stream,
76
- // doc_root,
77
- // options: { provider, openaiApiKey, groqApiKey, anthropicApiKey },
78
- // onToken: token => {
79
- // if (stream) process.stdout.write(token);
80
- // },
81
- // });
82
-
83
- // if (!stream) {
84
- // console.log("\n\n✅ Result:\n");
85
- // console.log(result.text);
86
- // console.log("\nMeta:", result.meta);
87
- // }
88
- // } catch (err) {
89
- // console.error("❌ Error running search:", err);
90
- // }
91
- // })();
51
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o-lang/semantic-doc-search",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "O-lang Semantic Document Search Resolver with hybrid search, embeddings, rerank, and streaming.",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
@@ -1,12 +1,11 @@
1
1
  // src/embeddings/anthropic.js
2
-
3
- import Anthropic from "@anthropic-ai/sdk";
2
+ const Anthropic = require("@anthropic-ai/sdk");
4
3
 
5
4
  /**
6
5
  * AnthropicEmbedding
7
6
  * Generates vector embeddings using Claude embeddings API.
8
7
  */
9
- export class AnthropicEmbedding {
8
+ class AnthropicEmbedding {
10
9
  constructor(apiKey = process.env.ANTHROPIC_API_KEY) {
11
10
  if (!apiKey) throw new Error("Missing ANTHROPIC_API_KEY");
12
11
  this.client = new Anthropic({ apiKey });
@@ -43,3 +42,5 @@ export class AnthropicEmbedding {
43
42
  return res.data.map(item => item.embedding);
44
43
  }
45
44
  }
45
+
46
+ module.exports = { AnthropicEmbedding };
@@ -1,6 +1,5 @@
1
1
  // src/embeddings/groq.js
2
-
3
- import Groq from "groq-sdk";
2
+ const Groq = require("groq-sdk");
4
3
 
5
4
  /**
6
5
  * GroqEmbedding
@@ -8,7 +7,7 @@ import Groq from "groq-sdk";
8
7
  *
9
8
  * Default model: nomic-embed-text
10
9
  */
11
- export class GroqEmbedding {
10
+ class GroqEmbedding {
12
11
  constructor(apiKey = process.env.GROQ_API_KEY) {
13
12
  if (!apiKey) throw new Error("Missing GROQ_API_KEY");
14
13
  this.client = new Groq({ apiKey });
@@ -45,3 +44,5 @@ export class GroqEmbedding {
45
44
  return res.data.map(item => item.embedding);
46
45
  }
47
46
  }
47
+
48
+ module.exports = { GroqEmbedding };
@@ -1,6 +1,5 @@
1
1
  // src/embeddings/openai.js
2
-
3
- import OpenAI from "openai";
2
+ const OpenAI = require("openai");
4
3
 
5
4
  /**
6
5
  * OpenAIEmbedding
@@ -8,7 +7,7 @@ import OpenAI from "openai";
8
7
  *
9
8
  * Default model: text-embedding-3-large (best for RAG)
10
9
  */
11
- export class OpenAIEmbedding {
10
+ class OpenAIEmbedding {
12
11
  constructor(apiKey = process.env.OPENAI_API_KEY) {
13
12
  if (!apiKey) throw new Error("Missing OPENAI_API_KEY");
14
13
  this.client = new OpenAI({ apiKey });
@@ -45,3 +44,5 @@ export class OpenAIEmbedding {
45
44
  return res.data.map(item => item.embedding);
46
45
  }
47
46
  }
47
+
48
+ module.exports = { OpenAIEmbedding };
@@ -1,12 +1,11 @@
1
1
  // src/rerank/cohere.js
2
-
3
- import Cohere from "cohere-ai";
2
+ const Cohere = require("cohere-ai");
4
3
 
5
4
  /**
6
5
  * CohereReranker
7
6
  * Uses Cohere Rerank API to reorder candidate documents/snippets
8
7
  */
9
- export class CohereReranker {
8
+ class CohereReranker {
10
9
  constructor(apiKey = process.env.COHERE_API_KEY) {
11
10
  if (!apiKey) throw new Error("Missing COHERE_API_KEY");
12
11
  Cohere.init(apiKey);
@@ -37,3 +36,5 @@ export class CohereReranker {
37
36
  return ranked;
38
37
  }
39
38
  }
39
+
40
+ module.exports = { CohereReranker };
@@ -1,12 +1,11 @@
1
1
  // src/rerank/groqRerank.js
2
-
3
- import Groq from "groq-sdk";
2
+ const Groq = require("groq-sdk");
4
3
 
5
4
  /**
6
5
  * GroqReranker
7
6
  * Uses Groq LLMs to rerank candidate documents/snippets given a query
8
7
  */
9
- export class GroqReranker {
8
+ class GroqReranker {
10
9
  constructor(apiKey = process.env.GROQ_API_KEY) {
11
10
  if (!apiKey) throw new Error("Missing GROQ_API_KEY");
12
11
  this.client = new Groq({ apiKey });
@@ -48,3 +47,5 @@ Return JSON array: [{"text": "...", "score": 0.95}, ...]
48
47
  }
49
48
  }
50
49
  }
50
+
51
+ module.exports = { GroqReranker };
@@ -1,12 +1,11 @@
1
1
  // src/rerank/local.js
2
-
3
- import { cosine } from "../utils/similarity.js";
2
+ const { cosine } = require("../utils/similarity.js");
4
3
 
5
4
  /**
6
5
  * LocalReranker
7
6
  * Simple fallback reranker using keyword overlap + cosine similarity
8
7
  */
9
- export class LocalReranker {
8
+ class LocalReranker {
10
9
  constructor() {}
11
10
 
12
11
  /**
@@ -41,3 +40,5 @@ export class LocalReranker {
41
40
  return results;
42
41
  }
43
42
  }
43
+
44
+ module.exports = { LocalReranker };
@@ -1,8 +1,7 @@
1
1
  // src/utils/fileLoader.js
2
-
3
- import fs from "fs";
4
- import path from "path";
5
- import { extractTextFromFile } from "./extractText.js";
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const { extractTextFromFile } = require("./extractText.js");
6
5
 
7
6
  /**
8
7
  * loadDocuments
@@ -13,7 +12,7 @@ import { extractTextFromFile } from "./extractText.js";
13
12
  * @param {string[]} exts - array of supported file extensions
14
13
  * @returns {Promise<Array<{ filePath: string, text: string }>>}
15
14
  */
16
- export async function loadDocuments(dirPath, exts = [".txt", ".md", ".pdf", ".html", ".docx"]) {
15
+ async function loadDocuments(dirPath, exts = [".txt", ".md", ".pdf", ".html", ".docx"]) {
17
16
  if (!fs.existsSync(dirPath)) return [];
18
17
 
19
18
  const files = fs.readdirSync(dirPath, { withFileTypes: true });
@@ -37,3 +36,5 @@ export async function loadDocuments(dirPath, exts = [".txt", ".md", ".pdf", ".ht
37
36
 
38
37
  return docs;
39
38
  }
39
+
40
+ module.exports = { loadDocuments };