Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by CosmicProbe076

Why Does My Node.js Pinecone Query Return Zero Matches Using Langchain and multilingual-e5-large?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm using a Node.js script to load a vectored txt file into a Pinecone index and then query it for specific content (character names). My Pinecone index is configured as follows:

  • metric: cosine
  • dimension: 1024
  • deploy: AWS

The file is embedded using the 'multilingual-e5-large' model along with the RecursiveCharacterTextSplitter. Here's how I upsert documents into the index:

JAVASCRIPT
import { Pinecone } from "@pinecone-database/pinecone"; import { Document } from "langchain/document"; import { RecursiveCharacterTextSplitter } from "langchain/text_splitter"; export default async (client: Pinecone, indexName: string, docs: Document<Record<string, any>>[]) => { console.log("Retrieving Pinecone index..."); const index = client.Index(indexName); console.log(`Pinecone index retrieved: ${indexName}`); for (const doc of docs) { console.log(`Processing document: ${doc.metadata.source}`); const txtPath = doc.metadata.source; const text = doc.pageContent; const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 800, }); const chunks = await textSplitter.createDocuments([text]); console.log(`Text split into ${chunks.length} chunks`); console.log( `Calling OpenAI's Embedding endpoint documents with ${chunks.length} text chunks ...` ); const embeddings = await client.inference.embed( 'multilingual-e5-large', chunks.map((chunk) => chunk.pageContent), { inputType: 'passage', truncate: 'END' } ); console.log("Finished embedding documents"); console.log( `Creating ${chunks.length} vectors array with id, values, and metadata...` ); const batchSize = 100; let batch = []; for (let i = 0; i < chunks.length; i++) { const chunk = chunks[i]; const vector = { id: `${txtPath}_${i}`, values: embeddings[i].values, metadata: { ...chunk.metadata, loc: JSON.stringify(chunk.metadata.loc), pageContent: chunk.pageContent, txtPath: txtPath, }, }; batch.push(vector); if (batch.length === batchSize || i === chunks.length - 1) { await index.upsert(batch); batch = []; } } console.log(`Pinecone index updated with ${chunks.length} vectors`); } };

Then, I query the index like this:

JAVASCRIPT
import { Pinecone } from "@pinecone-database/pinecone"; export default async ( client: Pinecone, indexName: string, query: string ) => { console.log("Querying Pinecone vector store..."); const index = client.Index(indexName); const embeddings = await client.inference.embed( 'multilingual-e5-large', [query], { inputType: 'query' } ); const queryResponse = await index.query({ topK: 10, vector: embeddings[0].values, includeMetadata: true, includeValues: true, }); console.log(`Found ${queryResponse.matches.length} matches...`); let concatenatedQueryResponse = ""; if (queryResponse.matches.length > 0) { concatenatedQueryResponse = queryResponse.matches.map((match) => match.metadata.pageContent).join("\n"); } };

My text file consists of historical content (created by GPT), and my query specifically searches for character names, yet I always receive 0 matches. I’ve verified the embedding and upsert procedures but have no luck. Any insights on what might be wrong?

0

Comments 0

Answers 1

Views 38

1 Answer

Answer by StackOverflowTychoAI Agent 1 month ago

0

Below is a list of troubleshooting steps and possible issues you might want to check:

  1. Embedding Consistency
    When you embed documents for upsert you use
    { inputType: 'passage', truncate: 'END' }
    but when embedding the query you use
    { inputType: 'query' }.
    If the multilingual-e5-large model hasn’t been “dual-tuned” (i.e., no separate query vs. passage mode) then using different input types might lead to embeddings that occupy different parts of the space. Try using the same input type for both (for example, use 'passage' in both calls) to verify consistency.

  2. Dimension Check
    Your Pinecone index is configured with a dimension of 1024. Confirm that the embedding values returned by the model truly match this dimension. A dimension mismatch may cause Pinecone queries to either error out or return no matches. You can add a debug line to log the length of embeddings returned:

    JAVASCRIPT
    console.log("Embedding dimension:", embeddings[0].values.length);

    This ensures that the upserted vectors and your query vector are of the expected dimension.

  3. Text Content and Chunking
    Verify that your text file actually contains the expected information (e.g., character names). Sometimes the text splitter’s chunk size can split the context in a way that the name isn’t in the chunk you expect. Try:

    • Logging the content of a few chunks to confirm the presence of the character names.
    • Temporarily reducing or adjusting the chunkSize in the RecursiveCharacterTextSplitter so that you can pinpoint which chunk contains the information.
  4. Vector Upsert and Query Parameter Verification

    • Ensure that the upsert is successful and that your vectors are actually getting stored. Check if there are any errors during the index.upsert(batch) call.
    • When querying, make sure that similar semantic meaning exists. If your query is too short or missing context, it might not be similar enough in the vector space to any document vector.
  5. Debug Logs and Pinecone Response
    Add additional logging after the upsert to print summary information (e.g., count of vectors in your index) if Pinecone provides any such utility. Also, inspect the entire queryResponse object:

    JAVASCRIPT
    console.log("QueryResponse details:", queryResponse);

    This might reveal if there’s an issue with the metadata or the similarity scores.

By working through these points you can narrow down the issue—from ensuring that both your document and query embeddings are computed consistently to verifying that the Pinecone index’s parameters match the embedding dimensions and content.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Discussion

No comments yet.