pgvector-template 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/PKG-INFO +1 -1
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/core/search.py +8 -10
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/service/document_service.py +6 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template.egg-info/PKG-INFO +1 -1
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pyproject.toml +1 -1
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/LICENSE +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/README.md +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/__init__.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/core/__init__.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/core/document.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/core/embedder.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/core/manager.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/db/__init__.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/db/connection.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/db/document_db.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/service/__init__.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/types.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/utils/__init__.py +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template.egg-info/SOURCES.txt +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template.egg-info/dependency_links.txt +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template.egg-info/requires.txt +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template.egg-info/top_level.txt +0 -0
- {pgvector_template-0.2.0 → pgvector_template-0.2.1}/setup.cfg +0 -0
|
@@ -109,22 +109,21 @@ class BaseSearchClient:
|
|
|
109
109
|
"""
|
|
110
110
|
db_query = select(self.config.document_cls)
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
if query.text:
|
|
113
|
+
db_query = self._apply_semantic_search(db_query, query)
|
|
114
114
|
db_query = self._apply_keyword_search(db_query, query)
|
|
115
115
|
# if query.metadata_filters:
|
|
116
116
|
# db_query = self._apply_metadata_filters(db_query, query)
|
|
117
117
|
db_query = db_query.limit(query.limit)
|
|
118
118
|
|
|
119
|
-
#
|
|
119
|
+
# execute query and return results
|
|
120
120
|
results = self.session.scalars(db_query).all()
|
|
121
|
-
|
|
122
|
-
# Convert to RetrievalResult objects
|
|
123
121
|
return self._convert_to_retrieval_results(results)
|
|
124
122
|
|
|
125
123
|
def _apply_semantic_search(self, query: Select, search_query: SearchQuery) -> Select:
|
|
126
124
|
"""Apply semantic (vector) search criteria to the query.
|
|
127
125
|
`embedding_provider` must be provided at instantiation, or an `ValueError` will be raised.
|
|
126
|
+
In PGVector, `<=>` operator is used to compare cosine distance. Lower = more similar.
|
|
128
127
|
|
|
129
128
|
Args:
|
|
130
129
|
query: The base SQLAlchemy query.
|
|
@@ -133,11 +132,10 @@ class BaseSearchClient:
|
|
|
133
132
|
Returns:
|
|
134
133
|
Updated SQLAlchemy query with semantic search applied.
|
|
135
134
|
"""
|
|
136
|
-
if not
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
raise NotImplementedError
|
|
135
|
+
if not search_query.text:
|
|
136
|
+
return query
|
|
137
|
+
query_embedding = self.embedding_provider.embed_text(search_query.text)
|
|
138
|
+
return query.order_by(self.config.document_cls.embedding.cosine_distance(query_embedding))
|
|
141
139
|
|
|
142
140
|
def _apply_keyword_search(self, db_query: Select, search_query: SearchQuery) -> Select:
|
|
143
141
|
"""Apply keyword (full-text) search criteria to the query.
|
{pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template/service/document_service.py
RENAMED
|
@@ -53,6 +53,12 @@ class DocumentServiceConfig(BaseModel):
|
|
|
53
53
|
if type(self.search_client_cfg) is BaseSearchClientConfig:
|
|
54
54
|
self.search_client_cfg.document_cls = self.document_cls
|
|
55
55
|
|
|
56
|
+
# assign embedding_provider to CorpusManager & SearchClient configs
|
|
57
|
+
if not self.corpus_manager_cfg.embedding_provider:
|
|
58
|
+
self.corpus_manager_cfg.embedding_provider = self.embedding_provider
|
|
59
|
+
if not self.search_client_cfg.embedding_provider:
|
|
60
|
+
self.search_client_cfg.embedding_provider = self.embedding_provider
|
|
61
|
+
|
|
56
62
|
model_config = {"arbitrary_types_allowed": True}
|
|
57
63
|
|
|
58
64
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pgvector-template"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Template library for flexible PGVector RAG implementations"
|
|
9
9
|
authors = [{ name="DL", email="v49t9zpqd@mozmail.com" }]
|
|
10
10
|
license = { text = "MIT" }
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{pgvector_template-0.2.0 → pgvector_template-0.2.1}/pgvector_template.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|