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 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
4 changes: 2 additions & 2 deletions lib/langchain/vectorsearch/pinecone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ 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)
search_results = similarity_search(query: question, namespace: namespace, filter: filter)
def ask(question:, namespace: "", filter: nil, k: 4, &block)
search_results = similarity_search(query: question, namespace: namespace, filter: filter, k: k)

context = search_results.map do |result|
result.dig("metadata").to_s
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