Skip to content

chore: performing sparse search with query expansion in langchain #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

bruvduroiu
Copy link
Contributor

Problem

Showcase the use of Pinecone sparse embeddings and sparse indexes for in situations where dense vector search might miss specific technical terms.

Solution

  • use Pinecone sparse embeddings
  • use query expansion technique
  • allow Langchain agent to search for specific technical terms from general queries ("Which tech companies were top performers this week?" transforms into vector search about "GOOGL performance", "NVIDIA Performance", ...

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (updates to documentation)

Test Plan

Describe specific steps for validating this change.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@jamescalam
Copy link
Collaborator

jamescalam commented May 12, 2025

  • move imports to the cells that they're used — it makes it easier for the user to see where various objects etc of coming from as they're working through the code
  • swap to using HF datasets
  • the cell where you're setting up the index is too complicated — it needs breaking apart and simplifying, see other code examples (such as rag-chatbot.ipynb) — try to avoid doing multiple actions in a single cell and if we do, explain each new step with a comment above/next to the code
  • explanation in markdown on "here we are setting up the index, dimension is None because X, metric, etc" — also need to point people to where to get their API keys and setup as we do in other notebooks
  • missing explanation of what @tool is doing and why we need it
  • random from langchain.memory import ConversationBufferMemory and from langchain.agents import create_tool_calling_agent, AgentExecutor imports mid-cell
  • expansion_llm = ChatOpenAI(temperature=0.7) used in query expansion tool can be a smaller LLM imo, either gpt-4.1-nano or gpt-4.1-mini — using smaller model also shows another reason why we might use query expansion as a separate tool rather than just built in to the prompting etc
  • we shouldn't use create_tool_calling_agent — better use LCEL, can refer to aurelio langchain course code
  • might be a good idea to explicitly define which model we're using for llm = ChatOpenAI()

@jamescalam jamescalam changed the base branch from master to james/sparse-example May 29, 2025 11:32
@jamescalam jamescalam merged commit 9c59591 into pinecone-io:james/sparse-example May 29, 2025
4 checks passed
@jamescalam
Copy link
Collaborator

moving to in-repo PR

jamescalam added a commit that referenced this pull request May 29, 2025
…) (#453)

## Problem

Showcase the use of Pinecone sparse embeddings and sparse indexes for in
situations where dense vector search might miss specific technical
terms.

## Solution

- use Pinecone sparse embeddings
- use query expansion technique
- allow Langchain agent to search for specific technical terms from
general queries ("Which tech companies were top performers this week?"
transforms into vector search about "GOOGL performance", "NVIDIA
Performance", ...

## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [X] None of the above: (updates to documentation)

## Test Plan

Describe specific steps for validating this change.

---------

## Problem

Describe the purpose of this change. What problem is being solved and
why?

## Solution

Describe the approach you took. Link to any relevant bugs, issues, docs,
or other resources.

## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [ ] None of the above: (explain here)

## Test Plan

Describe specific steps for validating this change.

---------

Co-authored-by: Bogdan Buduroiu <panini-croaky.0m@icloud.com>
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.

2 participants