Fix from_embeddings method examples (#3174)

Fix examples for `from_embeddings` method for annoy and faiss
vectorstores
This commit is contained in:
Adilzhan Ismailov 2023-04-20 04:49:33 +01:00 committed by GitHub
parent f19b3890c9
commit c03a65c6dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -367,7 +367,9 @@ class Annoy(VectorStore):
from langchain import Annoy
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
db = Annoy.from_texts(texts, embeddings)
text_embeddings = embeddings.embed_documents(texts)
text_embedding_pairs = list(zip(texts, text_embeddings))
db = Annoy.from_embeddings(text_embedding_pairs, embeddings)
"""
texts = [t[0] for t in text_embeddings]
embeddings = [t[1] for t in text_embeddings]

View File

@ -396,7 +396,9 @@ class FAISS(VectorStore):
from langchain import FAISS
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
faiss = FAISS.from_texts(texts, embeddings)
text_embeddings = embeddings.embed_documents(texts)
text_embedding_pairs = list(zip(texts, text_embeddings))
faiss = FAISS.from_embeddings(text_embedding_pairs, embeddings)
"""
texts = [t[0] for t in text_embeddings]
embeddings = [t[1] for t in text_embeddings]