Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const config: ConfigArray = [
"@typescript-eslint/no-floating-promises": "off",
"no-instanceof/no-instanceof": "off",
"@typescript-eslint/no-misused-promises": "off",
"import/no-extraneous-dependencies": "off",
},
},
];
Expand Down
7 changes: 4 additions & 3 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"dotenv": "^16.0.3",
"duck-duck-scrape": "^2.2.5",
"exa-js": "^1.0.12",
"firebase-admin": "^12.0.0",
"firebase-admin": "^13.0.0",
"graphql": "^16.6.0",
"hdb": "^0.19.8",
"ioredis": "^5.3.2",
Expand All @@ -100,14 +100,13 @@
"lunary": "^0.8.8",
"mariadb": "^3.4.0",
"mem0ai": "^2.1.8",
"mongodb": "^6.17.0",
"mongodb": "^6.20.0",
"pg": "^8.16.3",
"pickleparser": "^0.2.1",
"prisma": "^4.11.0",
"readline": "^1.3.0",
"redis": "^4.6.13",
"sqlite3": "^5.1.4",
"typeorm": "^0.3.20",
"typesense": "^1.5.3",
"uuid": "^10.0.0",
"voy-search": "0.6.2",
Expand Down Expand Up @@ -150,7 +149,9 @@
"@types/uuid": "^9",
"eslint": "^9.34.0",
"prettier": "^2.8.3",
"reflect-metadata": "^0.2.2",
"tsx": "^3.12.3",
"typeorm": "^0.3.20",
"typescript": "~5.1.6",
"zod": "^3.25.76"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from "@jest/globals";
import { test, expect } from "vitest";

import { OpenAPIV3, OpenAPIV3_1 } from "openapi-types";
import {
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { langchainConfig } from "@langchain/eslint";

export default langchainConfig;
export default langchainConfig;
4 changes: 2 additions & 2 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"eslint": "^9.34.0",
"faiss-node": "^0.5.1",
"fast-xml-parser": "^4.5.1",
"firebase-admin": "^11.9.0 || ^12.0.0",
"firebase-admin": "^11.9.0 || ^12.0.0 || ^13.0.0",
"google-auth-library": "^9.10.0",
"googleapis": "^126.0.1",
"graphql": "^16.6.0",
Expand Down Expand Up @@ -279,7 +279,7 @@
"epub2": "^3.0.1",
"faiss-node": "*",
"fast-xml-parser": "*",
"firebase-admin": "^11.9.0 || ^12.0.0",
"firebase-admin": "^11.9.0 || ^12.0.0 || ^13.0.0",
"google-auth-library": "*",
"googleapis": "*",
"hnswlib-node": "^3.0.0",
Expand Down
16 changes: 12 additions & 4 deletions libs/langchain-community/src/document_loaders/web/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,9 @@ export class JiraDocumentConverter {
export interface JiraProjectLoaderParams {
host: string;
projectKey: string;
username: string;
accessToken: string;
username?: string;
accessToken?: string;
personalAccessToken?: string;
limitPerRequest?: number;
createdAfter?: Date;
}
Expand All @@ -330,27 +331,30 @@ const API_ENDPOINTS = {
* Class representing a document loader for loading pages from Confluence.
*/
export class JiraProjectLoader extends BaseDocumentLoader {
private readonly accessToken: string;
private readonly accessToken?: string;

public readonly host: string;

public readonly projectKey: string;

public readonly username: string;
public readonly username?: string;

public readonly limitPerRequest: number;

private readonly createdAfter?: Date;

private readonly documentConverter: JiraDocumentConverter;

private readonly personalAccessToken?: string;

constructor({
host,
projectKey,
username,
accessToken,
limitPerRequest = 100,
createdAfter,
personalAccessToken,
}: JiraProjectLoaderParams) {
super();
this.host = host;
Expand All @@ -360,9 +364,13 @@ export class JiraProjectLoader extends BaseDocumentLoader {
this.limitPerRequest = limitPerRequest;
this.createdAfter = createdAfter;
this.documentConverter = new JiraDocumentConverter({ host, projectKey });
this.personalAccessToken = personalAccessToken;
}

private buildAuthorizationHeader(): string {
if (this.personalAccessToken) {
return `Bearer ${this.personalAccessToken}`;
}
return `Basic ${Buffer.from(
`${this.username}:${this.accessToken}`
).toString("base64")}`;
Expand Down
7 changes: 6 additions & 1 deletion libs/langchain-community/src/embeddings/alibaba_tongyi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { chunkArray } from "@langchain/core/utils/chunk_array";

export interface AlibabaTongyiEmbeddingsParams extends EmbeddingsParams {
/** Model name to use */
modelName: "text-embedding-v2";
modelName:
| "multimodal-embedding-v1"
| "text-embedding-v1"
| "text-embedding-v2"
| "text-embedding-v3"
| "text-embedding-v4";

/**
* Timeout to use when making requests to AlibabaTongyi.
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/src/embeddings/zhipuai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface ZhipuAIEmbeddingsParams extends EmbeddingsParams {
/**
* Model Name to use
*/
modelName?: "embedding-2";
modelName?: "embedding-2" | "embedding-3";
/**
* ZhipuAI API key to use
*/
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain-community/src/indexes/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class PostgresRecordManager implements RecordManagerInterface {

async getTime(): Promise<number> {
const res = await this.pool.query(
"SELECT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)"
"SELECT EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) AS extract"
);
return Number.parseFloat(res.rows[0].extract);
}
Expand Down
2 changes: 2 additions & 0 deletions libs/langchain-community/src/load/import_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const optionalImportEntrypoints: string[] = [
"langchain_community/agents/toolkits/aws_sfn",
"langchain_community/agents/toolkits/ibm",
"langchain_community/agents/toolkits/stagehand",
"langchain_community/embeddings/alibaba_tongyi",
"langchain_community/embeddings/bedrock",
"langchain_community/embeddings/cloudflare_workersai",
"langchain_community/embeddings/cohere",
"langchain_community/embeddings/bytedance_doubao",
"langchain_community/embeddings/gradient_ai",
"langchain_community/embeddings/hf",
"langchain_community/embeddings/hf_transformers",
Expand Down
18 changes: 18 additions & 0 deletions libs/langchain-community/src/retrievers/tests/bm25.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from "@jest/globals";
import { Document } from "@langchain/core/documents";
import { BM25Retriever } from "../bm25.js";
import { getTermFrequency } from "../../utils/@furkantoprak/bm25/BM25.js";

test("BM25Retriever", async () => {
const docs = [
Expand All @@ -25,3 +26,20 @@ test("BM25Retriever", async () => {
"The quick brown fox jumps over the lazy dog"
);
});

test("getTermFrequency escapes regex metacharacters", () => {
const corpus =
"**Version 1:** What is the country of origin for the person in question?";
const term = "**Version 1:**";

// Should not throw and should find at least one match
const freq = getTermFrequency(term, corpus);
expect(freq).toBeGreaterThanOrEqual(1);

// Also test other metacharacters
const corpus2 = "Does this match (maybe)? [yes] *stars* +plus+";
expect(getTermFrequency("(maybe)?", corpus2)).toBeGreaterThanOrEqual(1);
expect(getTermFrequency("[yes]", corpus2)).toBeGreaterThanOrEqual(1);
expect(getTermFrequency("*stars*", corpus2)).toBeGreaterThanOrEqual(1);
expect(getTermFrequency("+plus+", corpus2)).toBeGreaterThanOrEqual(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const getWordCount = (corpus: string) => {

/** Number of occurences of a word in a string. */
export const getTermFrequency = (term: string, corpus: string) => {
return ((corpus || "").match(new RegExp(term, "g")) || []).length;
// Escape any RegExp metacharacters in the term so constructing a RegExp
// from user-provided or model-generated queries does not throw an error
const escaped = (term || "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return ((corpus || "").match(new RegExp(escaped, "g")) || []).length;
};

/** Inverse document frequency. */
Expand Down
4 changes: 3 additions & 1 deletion libs/langchain-community/src/vectorstores/milvus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ export class Milvus extends VectorStore {
});
desc.schema.fields.forEach((field) => {
this.fields.push(field.name);
if (field.autoID) {
// Only remove autoID fields from this.fields if we're using autoId mode
// When autoId is false, we need to include the primary field for upsert operations
if (field.autoID && this.autoId) {
const index = this.fields.indexOf(field.name);
if (index !== -1) {
this.fields.splice(index, 1);
Expand Down
Loading