langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
48 lines (47 loc) • 1.89 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../types");
const base_1 = require("../../base");
const vectorSearchPlugin_1 = __importDefault(require("../vectorSearch/vectorSearchPlugin"));
class OpenAIVectorSearchPlugin {
constructor() {
this.name = "openAIVectorSearch";
this.description = "Query a FAISS vector index using OpenAI embeddings.";
this.type = types_1.PluginType.VectorSearch;
this.RunConfigExample = {
query: ""
};
this.InitConfigExample = {
apiKey: "sk-...",
model: "text-embedding-3-small",
indexPath: "./data/faiss-index",
k: 3,
};
}
expose() {
return {
name: this.name,
description: this.description,
type: this.type,
InitConfigExample: this.InitConfigExample,
RunConfigExample: this.RunConfigExample,
retriever: this.retriever
};
}
async init(config) {
var _a;
const retriever = await (0, base_1.retrieverBuilder)({ embedding: { provider: types_1.EmbeddingProviders.OpenAI,
apiKey: config.apiKey,
model: config.model || "text-embedding-3-small"
}, store: { type: types_1.VectorStores.Faiss, indexPath: config.indexPath || "./data/faiss-index" }, k: (_a = config.k) !== null && _a !== void 0 ? _a : 4 });
this.retriever = retriever;
}
async run(args) {
const vectorSearchPlugin = new vectorSearchPlugin_1.default();
return await vectorSearchPlugin.run({ retriever: this.retriever, query: args.query });
}
}
exports.default = OpenAIVectorSearchPlugin;