Skip to content

Commit

Permalink
change content bases ElasticVectorSearch to ElasticsearchStore
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisoSouza committed May 20, 2024
1 parent 9985769 commit d54846c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import FastAPI
from langchain.embeddings import SagemakerEndpointEmbeddings, HuggingFaceHubEmbeddings, CohereEmbeddings
from langchain.embeddings.base import Embeddings
from langchain.vectorstores import ElasticVectorSearch, VectorStore
from langchain.vectorstores import ElasticVectorSearch, VectorStore, ElasticsearchStore

from app.handlers import IDocumentHandler
from app.handlers.products import ProductsHandler
Expand Down Expand Up @@ -71,8 +71,8 @@ def __init__(self, config: AppConfig):
self.products_handler = ProductsHandler(self.products_indexer)
self.api.include_router(self.products_handler.router)

self.content_base_vectorstore = ElasticVectorSearch(
elasticsearch_url=config.es_url,
self.content_base_vectorstore = ElasticsearchStore(
es_url=config.es_url,
index_name=config.content_base_index_name,
embedding=self.embeddings,
)
Expand Down
10 changes: 9 additions & 1 deletion app/store/elasticsearch_vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ class ContentBaseElasticsearchVectorStoreIndex(ElasticsearchVectorStoreIndex):

def save(self, docs: list[Document])-> list[str]:
index = os.environ.get("INDEX_CONTENTBASES_NAME", "content_bases")
res = self.vectorstore.from_documents(docs, self.vectorstore.embeddings, index_name=index)
res = self.vectorstore.from_documents(
docs,
self.vectorstore.embeddings,
index_name=index,
bulk_kwargs={
"chunk_size": os.environ.get("DEFAULT_CHUNK_SIZE", 75),
"max_chunk_bytes": 200000000
}
)
return res

def query_search(self, search_filter: dict) -> list[dict]:
Expand Down

0 comments on commit d54846c

Please sign in to comment.