Spaces:
Sleeping
Sleeping
Léo Bourrel
commited on
Commit
·
47eff8b
1
Parent(s):
5ac52b0
clean: ruff
Browse files- chat_history.py +4 -1
- custom_pgvector.py +7 -10
chat_history.py
CHANGED
@@ -35,7 +35,10 @@ def insert_chat_history_articles(
|
|
35 |
with Session(conn) as conn:
|
36 |
conn.execute(
|
37 |
text(
|
38 |
-
"
|
|
|
|
|
|
|
39 |
),
|
40 |
[
|
41 |
{
|
|
|
35 |
with Session(conn) as conn:
|
36 |
conn.execute(
|
37 |
text(
|
38 |
+
"""
|
39 |
+
INSERT INTO chat_history_articles (chat_history_id, article_id)
|
40 |
+
VALUES (:chat_history_id, :article_id) ON CONFLICT DO NOTHING;
|
41 |
+
"""
|
42 |
),
|
43 |
[
|
44 |
{
|
custom_pgvector.py
CHANGED
@@ -207,13 +207,10 @@ class CustomPGVector(VectorStore):
|
|
207 |
metadatas = [{} for _ in texts]
|
208 |
|
209 |
with Session(self._conn) as session:
|
210 |
-
|
211 |
-
# if not collection:
|
212 |
-
# raise ValueError("Collection not found")
|
213 |
-
for text, metadata, embedding, id in zip(texts, metadatas, embeddings, ids):
|
214 |
embedding_store = self.EmbeddingStore(
|
215 |
embedding=embedding,
|
216 |
-
document=
|
217 |
cmetadata=metadata,
|
218 |
custom_id=id,
|
219 |
)
|
@@ -405,7 +402,7 @@ class CustomPGVector(VectorStore):
|
|
405 |
|
406 |
@classmethod
|
407 |
def from_texts(
|
408 |
-
cls: Type[
|
409 |
texts: List[str],
|
410 |
embedding: Embeddings,
|
411 |
metadatas: Optional[List[dict]] = None,
|
@@ -414,7 +411,7 @@ class CustomPGVector(VectorStore):
|
|
414 |
ids: Optional[List[str]] = None,
|
415 |
pre_delete_collection: bool = False,
|
416 |
**kwargs: Any,
|
417 |
-
) ->
|
418 |
"""
|
419 |
Return VectorStore initialized from texts and embeddings.
|
420 |
Postgres connection string is required
|
@@ -446,7 +443,7 @@ class CustomPGVector(VectorStore):
|
|
446 |
ids: Optional[List[str]] = None,
|
447 |
pre_delete_collection: bool = False,
|
448 |
**kwargs: Any,
|
449 |
-
) ->
|
450 |
"""Construct PGVector wrapper from raw documents and pre-
|
451 |
generated embeddings.
|
452 |
|
@@ -482,13 +479,13 @@ class CustomPGVector(VectorStore):
|
|
482 |
|
483 |
@classmethod
|
484 |
def from_existing_index(
|
485 |
-
cls: Type[
|
486 |
embedding: Embeddings,
|
487 |
table_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
|
488 |
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
489 |
pre_delete_collection: bool = False,
|
490 |
**kwargs: Any,
|
491 |
-
) ->
|
492 |
"""
|
493 |
Get intsance of an existing PGVector store.This method will
|
494 |
return the instance of the store without inserting any new
|
|
|
207 |
metadatas = [{} for _ in texts]
|
208 |
|
209 |
with Session(self._conn) as session:
|
210 |
+
for txt, metadata, embedding, id in zip(texts, metadatas, embeddings, ids):
|
|
|
|
|
|
|
211 |
embedding_store = self.EmbeddingStore(
|
212 |
embedding=embedding,
|
213 |
+
document=txt,
|
214 |
cmetadata=metadata,
|
215 |
custom_id=id,
|
216 |
)
|
|
|
402 |
|
403 |
@classmethod
|
404 |
def from_texts(
|
405 |
+
cls: Type[CustomPGVector],
|
406 |
texts: List[str],
|
407 |
embedding: Embeddings,
|
408 |
metadatas: Optional[List[dict]] = None,
|
|
|
411 |
ids: Optional[List[str]] = None,
|
412 |
pre_delete_collection: bool = False,
|
413 |
**kwargs: Any,
|
414 |
+
) -> CustomPGVector:
|
415 |
"""
|
416 |
Return VectorStore initialized from texts and embeddings.
|
417 |
Postgres connection string is required
|
|
|
443 |
ids: Optional[List[str]] = None,
|
444 |
pre_delete_collection: bool = False,
|
445 |
**kwargs: Any,
|
446 |
+
) -> CustomPGVector:
|
447 |
"""Construct PGVector wrapper from raw documents and pre-
|
448 |
generated embeddings.
|
449 |
|
|
|
479 |
|
480 |
@classmethod
|
481 |
def from_existing_index(
|
482 |
+
cls: Type[CustomPGVector],
|
483 |
embedding: Embeddings,
|
484 |
table_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
|
485 |
distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
|
486 |
pre_delete_collection: bool = False,
|
487 |
**kwargs: Any,
|
488 |
+
) -> CustomPGVector:
|
489 |
"""
|
490 |
Get intsance of an existing PGVector store.This method will
|
491 |
return the instance of the store without inserting any new
|