mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-18 10:43:36 +00:00
Fixes scope of query Session in PGVector (#5194)
`vectorstore.PGVector`: The transactional boundary should be increased to cover the query itself Currently, within the `similarity_search_with_score_by_vector` the transactional boundary (created via the `Session` call) does not include the select query being made. This can result in un-intended consequences when interacting with the PGVector instance methods directly --------- Co-authored-by: Dev 2049 <dev.dev2049@gmail.com>
This commit is contained in:
parent
52714cedd4
commit
c173bf1c62
@ -298,15 +298,17 @@ class PGVector(VectorStore):
|
|||||||
for key, value in filter.items():
|
for key, value in filter.items():
|
||||||
IN = "in"
|
IN = "in"
|
||||||
if isinstance(value, dict) and IN in map(str.lower, value):
|
if isinstance(value, dict) and IN in map(str.lower, value):
|
||||||
value_case_insensitive = {k.lower(): v for k, v in value.items()}
|
value_case_insensitive = {
|
||||||
|
k.lower(): v for k, v in value.items()
|
||||||
|
}
|
||||||
filter_by_metadata = EmbeddingStore.cmetadata[key].astext.in_(
|
filter_by_metadata = EmbeddingStore.cmetadata[key].astext.in_(
|
||||||
value_case_insensitive[IN]
|
value_case_insensitive[IN]
|
||||||
)
|
)
|
||||||
filter_clauses.append(filter_by_metadata)
|
filter_clauses.append(filter_by_metadata)
|
||||||
else:
|
else:
|
||||||
filter_by_metadata = EmbeddingStore.cmetadata[key].astext == str(
|
filter_by_metadata = EmbeddingStore.cmetadata[
|
||||||
value
|
key
|
||||||
)
|
].astext == str(value)
|
||||||
filter_clauses.append(filter_by_metadata)
|
filter_clauses.append(filter_by_metadata)
|
||||||
|
|
||||||
filter_by = sqlalchemy.and_(filter_by, *filter_clauses)
|
filter_by = sqlalchemy.and_(filter_by, *filter_clauses)
|
||||||
@ -325,6 +327,7 @@ class PGVector(VectorStore):
|
|||||||
.limit(k)
|
.limit(k)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|
||||||
docs = [
|
docs = [
|
||||||
(
|
(
|
||||||
Document(
|
Document(
|
||||||
|
Loading…
Reference in New Issue
Block a user