Skip to content

DA-831: Update LangChain to use CouchbaseSearchVectorStore#8

Open
ejscribner wants to merge 2 commits intomainfrom
DA-831/update-langchain-use-search-vectorstore
Open

DA-831: Update LangChain to use CouchbaseSearchVectorStore#8
ejscribner wants to merge 2 commits intomainfrom
DA-831/update-langchain-use-search-vectorstore

Conversation

@ejscribner
Copy link

After deprecating CouchbaseVectorStore in favor of CouchbaseSearchVectorStore and CouchbaseQueryVectorStore, we need to update all dependents that use CouchbaseVectorStore to use CouchbaseSearchVectorStore. Ref: https://jira.issues.couchbase.com/browse/DA-831

This PR includes several other usability improvements as well.

@vercel
Copy link

vercel bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vector-search-nodejs Error Error Feb 5, 2026 6:24pm

@gemini-code-assist
Copy link

Summary of Changes

Hello @ejscribner, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on modernizing the application's integration with LangChain and Couchbase, specifically by migrating to the recommended CouchbaseSearchVectorStore. This change ensures compatibility with current best practices and leverages updated LangChain features. Beyond the core migration, the PR also enhances the application's robustness through improved environment variable handling, better error reporting for database connections, and refactors UI components for a smoother user experience with React Suspense.

Highlights

  • Couchbase Vector Store Migration: The application has been updated to use CouchbaseSearchVectorStore instead of the deprecated CouchbaseVectorStore for vector operations, aligning with the latest LangChain recommendations.
  • LangChain Dependency Updates: Several LangChain related packages, including @langchain/community, @langchain/openai, @langchain/core, and langchain itself, have been updated to their latest versions, introducing new import paths and functionalities.
  • Environment Variable Handling & Error Management: Improved handling of environment variables for OpenAI API keys, including explicit loading and error responses for missing keys. The Couchbase connection now includes robust error handling for connection failures.
  • UI Component Refactoring for Suspense: The ChatPage and PDFUploader components have been refactored to use React's Suspense for better loading state management, particularly when dealing with useSearchParams.
  • Configuration and Documentation Updates: The .gitignore file has been updated to exclude IDE-specific files and .env files, and the README.md now includes a crucial note regarding the format of the Couchbase connection string.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .gitignore
    • Added .idea/ to ignore IDE-specific files.
    • Added .env to ignore local environment files.
    • Ensured a newline at the end of the file.
  • README.md
    • Updated instructions for setting environment secrets, adding a note that DB_CONN_STR must start with couchbase:// and should not contain the port number.
  • app/api/chat/route.ts
    • Replaced CouchbaseVectorStore with CouchbaseSearchVectorStore imports.
    • Updated LangChain chain imports from langchain/chains to @langchain/classic/chains.
    • Imported NextResponse for API responses.
    • Explicitly loaded OPENAI_API_KEY and added a check to return a 500 error if it's not set.
    • Passed openAIApiKey directly to ChatOpenAI and apiKey to OpenAIEmbeddings constructors.
    • Changed OpenAIEmbeddings model to text-embedding-3-small.
    • Added a null check for the Couchbase cluster connection.
    • Renamed couchbaseVectorStore to couchbaseSearchVectorStore and updated its initialization.
    • Added searchType: "similarity" and searchKwargs: { k: 4 } to the retriever configuration.
    • Temporarily changed createRetrievalChain to use retriever directly, skipping historyAwareRetrieverChain for debugging purposes.
    • Added a NextResponse.json error return in the catch block for chat processing failures.
  • app/api/ingestPdf/route.ts
    • Updated RecursiveCharacterTextSplitter import path from langchain/text_splitter to @langchain/textsplitters.
    • Replaced CouchbaseVectorStore with CouchbaseSearchVectorStore imports and updated its type arguments.
    • Added a null check for the Couchbase cluster connection.
    • Updated CouchbaseVectorStore.fromDocuments to CouchbaseSearchVectorStore.fromDocuments.
  • app/chatPage/page.tsx
    • Imported Suspense from 'react'.
    • Refactored the main ChatPage component into ChatContent and introduced a ChatPageContentWrapper to enable Suspense for useSearchParams.
  • components/PDFUploader.tsx
    • Imported Suspense from 'react'.
    • Refactored the main PDFUploader component into PDFUploaderContent and introduced a PDFUploaderWrapper to enable Suspense for useSearchParams.
  • lib/couchbase-connection.ts
    • Updated the return type of createCouchbaseCluster to Promise<Cluster | void> to reflect potential connection failures.
    • Wrapped the Couchbase connect call in a try-catch block to handle connection errors gracefully and throw a more informative error message.
  • package.json
    • Added @langchain/classic dependency.
    • Updated @langchain/community from ^0.3.5 to ^1.1.8.
    • Added @langchain/core dependency.
    • Updated @langchain/openai from ^0.3.7 to ^1.2.4.
    • Updated langchain from ^0.3.2 to ^1.2.2.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully updates the application to use CouchbaseSearchVectorStore instead of the deprecated CouchbaseVectorStore, and introduces several other valuable improvements such as better error handling and frontend performance optimizations with React Suspense. My review highlights a few areas for improvement: a piece of debugging code that alters functionality should be reverted, error responses could be more specific by including HTTP status codes, and there's an opportunity to correct a function's return type which would also allow for the removal of some redundant code.

Comment on lines 141 to 145
// Skip history-aware retriever for now to debug the issue
const conversationalRetrievalChain = await createRetrievalChain({
retriever: historyAwareRetrieverChain,
retriever: retriever,
combineDocsChain: documentChain,
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The history-aware retriever has been disabled, with a comment indicating this is for debugging. This is a significant functional change as the chat will no longer consider conversation history when retrieving documents. If this is a temporary measure, it should be reverted before merging. If the change is intentional, it should be clearly documented in the pull request description.

    const conversationalRetrievalChain = await createRetrievalChain({
      retriever: historyAwareRetrieverChain,
      combineDocsChain: documentChain,
    });

import { connect, Cluster } from "couchbase";

export async function createCouchbaseCluster(): Promise<Cluster> {
export async function createCouchbaseCluster(): Promise<Cluster | void> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The function's return type is declared as Promise<Cluster | void>, but it never resolves to void. It either returns a Promise<Cluster> on a successful connection or throws an error (resulting in a rejected promise). The return type should be Promise<Cluster> to accurately reflect the function's behavior.

Suggested change
export async function createCouchbaseCluster(): Promise<Cluster | void> {
export async function createCouchbaseCluster(): Promise<Cluster> {

Comment on lines +90 to +92
if (!cluster) {
throw new Error("Couchbase cluster connection failed");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check for !cluster is redundant. The createCouchbaseCluster function is designed to throw an error if the connection fails, which will be caught by the outer try...catch block in this POST handler. As a result, this if block is unreachable and can be safely removed.


} catch (err) {
console.log("Error Received ", err);
return NextResponse.json({ error: "Failed to process chat message" });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's good practice to include an HTTP status code with error responses. For a server-side failure like this, returning a 500 Internal Server Error status is more informative for clients and monitoring tools.

    return NextResponse.json({ error: "Failed to process chat message" }, { status: 500 });

Comment on lines +55 to +57
if (!cluster) {
throw new Error("Couchbase cluster connection failed");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check for !cluster is redundant. The createCouchbaseCluster function will throw an error if the connection fails, and this error will be caught by the try...catch block in this POST handler. Therefore, this if block is unreachable and can be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant