chore: Adjust Faiss Vector Store parameters format
This commit is contained in:
parent
9eccd0c43b
commit
e6e0649264
1 changed files with 30 additions and 42 deletions
|
|
@ -21,26 +21,24 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
||||||
icon = "FAISS"
|
icon = "FAISS"
|
||||||
|
|
||||||
inputs = [
|
inputs = [
|
||||||
StrInput(
|
|
||||||
name="folder_path",
|
|
||||||
display_name="Folder Path",
|
|
||||||
info="Path to save the FAISS index. It will be relative to where Langflow is running.",
|
|
||||||
),
|
|
||||||
StrInput(
|
StrInput(
|
||||||
name="index_name",
|
name="index_name",
|
||||||
display_name="Index Name",
|
display_name="Index Name",
|
||||||
value="langflow_index",
|
value="langflow_index",
|
||||||
),
|
),
|
||||||
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
StrInput(
|
||||||
DataInput(
|
name="persist_directory",
|
||||||
name="vector_store_inputs",
|
display_name="Persist Directory",
|
||||||
display_name="Vector Store Inputs",
|
info="Path to save the FAISS index. It will be relative to where Langflow is running.",
|
||||||
is_list=True,
|
|
||||||
),
|
),
|
||||||
BoolInput(
|
MultilineInput(
|
||||||
name="add_to_vector_store",
|
name="search_query",
|
||||||
display_name="Add to Vector Store",
|
display_name="Search Query",
|
||||||
info="If true, the Vector Store Inputs will be added to the Vector Store.",
|
),
|
||||||
|
DataInput(
|
||||||
|
name="ingest_data",
|
||||||
|
display_name="Ingest Data",
|
||||||
|
is_list=True,
|
||||||
),
|
),
|
||||||
BoolInput(
|
BoolInput(
|
||||||
name="allow_dangerous_deserialization",
|
name="allow_dangerous_deserialization",
|
||||||
|
|
@ -49,10 +47,7 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
||||||
advanced=True,
|
advanced=True,
|
||||||
value=True,
|
value=True,
|
||||||
),
|
),
|
||||||
MultilineInput(
|
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
||||||
name="search_input",
|
|
||||||
display_name="Search Input",
|
|
||||||
),
|
|
||||||
IntInput(
|
IntInput(
|
||||||
name="number_of_results",
|
name="number_of_results",
|
||||||
display_name="Number of Results",
|
display_name="Number of Results",
|
||||||
|
|
@ -66,27 +61,20 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
||||||
"""
|
"""
|
||||||
Builds the FAISS object.
|
Builds the FAISS object.
|
||||||
"""
|
"""
|
||||||
if not self.folder_path:
|
if not self.persist_directory:
|
||||||
raise ValueError("Folder path is required to save the FAISS index.")
|
raise ValueError("Folder path is required to save the FAISS index.")
|
||||||
path = self.resolve_path(self.folder_path)
|
path = self.resolve_path(self.persist_directory)
|
||||||
|
|
||||||
if self.add_to_vector_store:
|
documents = []
|
||||||
documents = []
|
|
||||||
for _input in self.vector_store_inputs or []:
|
|
||||||
if isinstance(_input, Data):
|
|
||||||
documents.append(_input.to_lc_document())
|
|
||||||
else:
|
|
||||||
documents.append(_input)
|
|
||||||
|
|
||||||
faiss = FAISS.from_documents(documents=documents, embedding=self.embedding)
|
for _input in self.ingest_data or []:
|
||||||
faiss.save_local(Text(path), self.index_name)
|
if isinstance(_input, Data):
|
||||||
else:
|
documents.append(_input.to_lc_document())
|
||||||
faiss = FAISS.load_local(
|
else:
|
||||||
folder_path=Text(path),
|
documents.append(_input)
|
||||||
embeddings=self.embedding,
|
|
||||||
index_name=self.index_name,
|
faiss = FAISS.from_documents(documents=documents, embedding=self.embedding)
|
||||||
allow_dangerous_deserialization=self.allow_dangerous_deserialization,
|
faiss.save_local(Text(path), self.index_name)
|
||||||
)
|
|
||||||
|
|
||||||
return faiss
|
return faiss
|
||||||
|
|
||||||
|
|
@ -94,12 +82,12 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
||||||
"""
|
"""
|
||||||
Search for documents in the FAISS vector store.
|
Search for documents in the FAISS vector store.
|
||||||
"""
|
"""
|
||||||
if not self.folder_path:
|
if not self.persist_directory:
|
||||||
raise ValueError("Folder path is required to load the FAISS index.")
|
raise ValueError("Folder path is required to load the FAISS index.")
|
||||||
path = self.resolve_path(self.folder_path)
|
path = self.resolve_path(self.persist_directory)
|
||||||
|
|
||||||
vector_store = FAISS.load_local(
|
vector_store = FAISS.load_local(
|
||||||
folder_path=Text(path),
|
persist_directory=Text(path),
|
||||||
embeddings=self.embedding,
|
embeddings=self.embedding,
|
||||||
index_name=self.index_name,
|
index_name=self.index_name,
|
||||||
allow_dangerous_deserialization=self.allow_dangerous_deserialization,
|
allow_dangerous_deserialization=self.allow_dangerous_deserialization,
|
||||||
|
|
@ -108,12 +96,12 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
||||||
if not vector_store:
|
if not vector_store:
|
||||||
raise ValueError("Failed to load the FAISS index.")
|
raise ValueError("Failed to load the FAISS index.")
|
||||||
|
|
||||||
logger.debug(f"Search input: {self.search_input}")
|
logger.debug(f"Search input: {self.search_query}")
|
||||||
logger.debug(f"Number of results: {self.number_of_results}")
|
logger.debug(f"Number of results: {self.number_of_results}")
|
||||||
|
|
||||||
if self.search_input and isinstance(self.search_input, str) and self.search_input.strip():
|
if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
|
||||||
docs = vector_store.similarity_search(
|
docs = vector_store.similarity_search(
|
||||||
query=self.search_input,
|
query=self.search_query,
|
||||||
k=self.number_of_results,
|
k=self.number_of_results,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue