Answers.Body: <p>Yes, you can do this. To directly quote the Faiss official <a href="https://github.com/facebookresearch/faiss/wiki#what-is-similarity-search" rel="nofollow noreferrer">documentation</a> for example, this tool can &quot;<em>return not just the nearest neighbor, but also the 2nd nearest, 3rd, ..., k-th nearest neighbor</em>&quot;.</p>
  <p>The code you've mentioned seems to be leveraging a langchain wrapper over Faiss. If you want the ability to determine the number of records (or neighbors) you'd like to retrieve, you might consider interacting with the primary Faiss Python library :</p>
  <pre><code>D, I = index.search(xq, k)
  </code></pre>
  <p>This command fetches the distances D and indices I of the k closest vectors to your query.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-15T06:45:31.740Z
Answers.Text: thanks for the reply. Do you know how I may be able to access this feature from langchain?
Answers.UserDisplayName: Karl 17302
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-15T10:36:08.913Z
Answers.Text: Sorry, I missed the "from langchain" part of your question. I think you might find some of the answers [here](https://stackoverflow.com/questions/76729793/how-to-specify-similarity-threshold-in-langchain-faiss-retriever#:~:text=You%20can%20use%20the%20following%20as%20a%20VectorStoreRetriever,retriever%20%3D%20dbFAISS.as_retriever%20%28search_type%3D%22similarity_score_threshold%22%2C%20search_kwargs%3D%20%7B%22score_threshold%22%3A.5%2C%20%22k%22%3A%20top_k%7D%29#:~:text=You%20can%20use%20the%20following,top_k) useful.
Answers.UserDisplayName: abkg
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-14T19:07:57.863Z
Answers.LastActivityDate: 2023-10-14T19:07:57.863Z
Answers.UserDisplayName: abkg
Body: <p>When using vector stores like pinecone or Faiss from langchain, is it possible to set the number of records returned based on similarity search?</p>
  <p>For example, consider the following code, is there a parameter that can be set to control number of rows returned?</p>
  <pre><code>FAISS.from_documents(mydata, embed_model)
  </code></pre>
  
Tags: <natural-language-processing><python><language-model>
Title: Setting number of rows returned by vector stores
UserDisplayName: Karl 17302
ThreadText: # Setting number of rows returned by vector stores
  
  (Asked by: username_0 on 2023-10-14)
  
  When using vector stores like pinecone or Faiss from langchain, is it possible to set the number of records returned based on similarity search?
  For example, consider the following code, is there a parameter that can be set to control number of rows returned?
  FAISS.from_documents(mydata, embed_model)
  
  **Tags:** natural-language-processing, python, language-model
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-10-14. Score: 0 | Accepted answer
  
  Yes, you can do this. To directly quote the Faiss official documentation for example, this tool can "return not just the nearest neighbor, but also the 2nd nearest, 3rd, ..., k-th nearest neighbor".
  The code you've mentioned seems to be leveraging a langchain wrapper over Faiss. If you want the ability to determine the number of records (or neighbors) you'd like to retrieve, you might consider interacting with the primary Faiss Python library :
  D, I = index.search(xq, k)
  
  This command fetches the distances D and indices I of the k closest vectors to your query.
  
  > **Comments:**
  > **username_0**: thanks for the reply. Do you know how I may be able to access this feature from langchain?  
  > **username_1**: Sorry, I missed the "from langchain" part of your question. I think you might find some of the answers [here](https://stackoverflow.com/questions/76729793/how-to-specify-similarity-threshold-in-langchain-faiss-retriever#:~:text=You%20can%20use%20the%20following%20as%20a%20VectorStoreRetriever,retriever%20%3D%20dbFAISS.as_retriever%20%28search_type%3D%22similarity_score_threshold%22%2C%20search_kwargs%3D%20%7B%22score_threshold%22%3A.5%2C%20%22k%22%3A%20top_k%7D%29#:~:text=You%20can%20use%20the%20following,top_k) useful.  
  
  ---
  
  