Skip to content
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

Add k to pinecone's "ask" functionality #297

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion lib/langchain/vectorsearch/pinecone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def similarity_search_by_vector(embedding:, k: 4, namespace: "", filter: nil)
# @param filter [String] The filter to use
# @yield [String] Stream responses back one String at a time
# @return [String] The answer to the question
def ask(question:, namespace: "", filter: nil, &block)
def ask(question:, namespace: "", filter: nil, k: 4, &block)
search_results = similarity_search(query: question, namespace: namespace, filter: filter)
Copy link
Collaborator

@andreibondarev andreibondarev Aug 21, 2023

Choose a reason for hiding this comment

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

I think you meant to also pass the k: param to the similarity_search(..., k: k)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 yes - absolutely did mean to do that. long day sorry.


context = search_results.map do |result|
Expand Down
7 changes: 4 additions & 3 deletions spec/langchain/vectorsearch/pinecone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,12 @@
let(:question) { "How many times is \"lorem\" mentioned in this text?" }
let(:prompt) { "Context:\n#{metadata}\n---\nQuestion: #{question}\n---\nAnswer:" }
let(:answer) { "5 times" }
let(:k) { 4 }

describe "without a namespace" do
before do
allow(subject).to receive(:similarity_search).with(
query: question, namespace: "", filter: nil
query: question, namespace: "", filter: nil, k: k
).and_return(matches)
allow(subject.llm).to receive(:chat).with(prompt: prompt).and_return(answer)
end
Expand All @@ -322,7 +323,7 @@
describe "with a namespace" do
before do
allow(subject).to receive(:similarity_search).with(
query: question, namespace: namespace, filter: nil
query: question, namespace: namespace, filter: nil, k: k
).and_return(matches)
allow(subject.llm).to receive(:chat).with(prompt: prompt).and_return(answer)
end
Expand All @@ -335,7 +336,7 @@
describe "with a filter" do
before do
allow(subject).to receive(:similarity_search).with(
query: question, namespace: "", filter: filter
query: question, namespace: "", filter: filter, k: k
).and_return(matches)
allow(subject.llm).to receive(:chat).with(prompt: prompt).and_return(answer)
end
Expand Down
Loading