pgvector-template 0.3.0__tar.gz → 0.3.2__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.
Files changed (27) hide show
  1. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/PKG-INFO +1 -1
  2. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/core/__init__.py +1 -3
  3. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/core/document.py +5 -2
  4. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/core/manager.py +16 -4
  5. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/core/search.py +3 -1
  6. pgvector_template-0.3.2/pgvector_template/models/__init__.py +1 -0
  7. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/models/search.py +18 -7
  8. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/service/__init__.py +1 -1
  9. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template.egg-info/PKG-INFO +1 -1
  10. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pyproject.toml +1 -1
  11. pgvector_template-0.3.0/pgvector_template/utils/__init__.py +0 -0
  12. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/LICENSE +0 -0
  13. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/README.md +0 -0
  14. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/__init__.py +0 -0
  15. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/core/embedder.py +0 -0
  16. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/db/__init__.py +0 -0
  17. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/db/connection.py +0 -0
  18. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/db/document_db.py +0 -0
  19. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/service/document_service.py +0 -0
  20. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/types.py +0 -0
  21. {pgvector_template-0.3.0/pgvector_template/models → pgvector_template-0.3.2/pgvector_template/utils}/__init__.py +0 -0
  22. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template/utils/metadata_filter.py +0 -0
  23. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template.egg-info/SOURCES.txt +0 -0
  24. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template.egg-info/dependency_links.txt +0 -0
  25. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template.egg-info/requires.txt +0 -0
  26. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/pgvector_template.egg-info/top_level.txt +0 -0
  27. {pgvector_template-0.3.0 → pgvector_template-0.3.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pgvector-template
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Template library for flexible PGVector RAG implementations
5
5
  Author-email: DL <v49t9zpqd@mozmail.com>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
1
  from pgvector_template.core.document import BaseDocument, BaseDocumentMetadata, BaseDocumentOptionalProps
2
2
  from pgvector_template.core.embedder import BaseEmbeddingProvider
3
3
  from pgvector_template.core.manager import BaseCorpusManager, BaseCorpusManagerConfig, Corpus
4
- from pgvector_template.core.search import SearchQuery, RetrievalResult, BaseSearchClientConfig, BaseSearchClient
4
+ from pgvector_template.core.search import BaseSearchClientConfig, BaseSearchClient
5
5
 
6
6
 
7
7
  __all__ = [
@@ -16,8 +16,6 @@ __all__ = [
16
16
  "BaseCorpusManager",
17
17
  "BaseCorpusManagerConfig",
18
18
  ### search
19
- "SearchQuery",
20
- "RetrievalResult",
21
19
  "BaseSearchClientConfig",
22
20
  "BaseSearchClient",
23
21
  ]
@@ -195,9 +195,12 @@ class BaseDocumentMetadata(BaseModel):
195
195
  """
196
196
 
197
197
  document_type: str = Field(
198
- ..., description="Description for type of document, e.g. markdown, pdf, etc"
198
+ ..., description="Original document type/format/extension, e.g. md, pdf, html, json, etc"
199
+ )
200
+ schema_version: str = Field(
201
+ default="1.0",
202
+ description="Schema version for the metadata. Intended for housekeeping only",
199
203
  )
200
- schema_version: str = Field(default="1.0", description="Schema version for the metadata")
201
204
 
202
205
  def to_dict(self) -> dict[str, Any]:
203
206
  return self.model_dump()
@@ -1,7 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from dataclasses import dataclass
3
3
  from logging import getLogger
4
- from typing import Any, Type
4
+ from typing import Any, Literal, Type
5
5
  from uuid import UUID, uuid4
6
6
 
7
7
  from pydantic import BaseModel, Field
@@ -111,6 +111,7 @@ class BaseCorpusManager(ABC):
111
111
  corpus_metadata: dict[str, Any],
112
112
  optional_props: BaseDocumentOptionalProps | None = None,
113
113
  corpus_id: UUID | str | None = None,
114
+ update_if_exists: bool = True,
114
115
  **kwargs,
115
116
  ) -> int:
116
117
  """
@@ -130,7 +131,12 @@ class BaseCorpusManager(ABC):
130
131
  document_contents = self._split_corpus(content)
131
132
  document_embeddings = self.embedding_provider.embed_batch(document_contents)
132
133
  return self.insert_documents(
133
- corpus_id, document_contents, document_embeddings, corpus_metadata, optional_props
134
+ corpus_id,
135
+ document_contents,
136
+ document_embeddings,
137
+ corpus_metadata,
138
+ optional_props,
139
+ update_if_exists,
134
140
  )
135
141
 
136
142
  def insert_documents(
@@ -140,6 +146,7 @@ class BaseCorpusManager(ABC):
140
146
  document_embeddings: list[list[float]],
141
147
  corpus_metadata: dict[str, Any],
142
148
  optional_props: BaseDocumentOptionalProps | None = None,
149
+ update_if_exists: bool = True,
143
150
  **kwargs,
144
151
  ) -> int:
145
152
  """
@@ -176,7 +183,12 @@ class BaseCorpusManager(ABC):
176
183
  optional_props=optional_props,
177
184
  )
178
185
  )
179
- self.session.add_all(documents_to_insert)
186
+
187
+ if update_if_exists:
188
+ for doc in documents_to_insert:
189
+ self.session.merge(doc)
190
+ else:
191
+ self.session.add_all(documents_to_insert)
180
192
  self.session.commit()
181
193
  return len(documents_to_insert)
182
194
 
@@ -189,7 +201,7 @@ class BaseCorpusManager(ABC):
189
201
  logger.warning(
190
202
  "Using default _split_corpus. Override this method to improve performance."
191
203
  )
192
- split_content = [content[i : i + 1000] for i in range(0, len(content), 1000)]
204
+ split_content = [content[i : i + 1024 * 4] for i in range(0, len(content), 1024 * 4)]
193
205
  return [c for c in split_content if len(c.strip()) > 0]
194
206
 
195
207
  def _join_documents(
@@ -138,7 +138,9 @@ class BaseSearchClient:
138
138
 
139
139
  # strictly speaking, this validation step is optional. You may override this method to disable
140
140
  try:
141
- validate_metadata_filters(search_query.metadata_filters, self.config.document_metadata_cls)
141
+ validate_metadata_filters(
142
+ search_query.metadata_filters, self.config.document_metadata_cls
143
+ )
142
144
  except ValueError as e:
143
145
  logger.warning(f"Metadata filter validation failed: {e}. Query success not guaranteed!")
144
146
 
@@ -0,0 +1 @@
1
+ from pgvector_template.models.search import *
@@ -1,17 +1,17 @@
1
1
  from dataclasses import dataclass, asdict
2
2
  from datetime import datetime
3
- from typing import Any, Literal
3
+ from typing import Any, Literal, Type
4
4
 
5
5
  from pydantic import BaseModel, ConfigDict, Field, model_validator
6
6
 
7
- from pgvector_template.core import BaseDocument
7
+ from pgvector_template.core import BaseDocument, BaseDocumentMetadata
8
8
 
9
9
 
10
10
  class MetadataFilter(BaseModel):
11
11
  """
12
12
  An object acting as a filter for an arbitrary `Metadata` dictionary/map/object.
13
13
  """
14
-
14
+
15
15
  field_name: str
16
16
  """Field path in metadata. Use dot notation for nested fields (e.g., 'publication_info.journal')"""
17
17
  condition: Literal["eq", "gt", "gte", "lt", "lte", "contains", "in", "exists"]
@@ -31,14 +31,22 @@ class MetadataFilter(BaseModel):
31
31
 
32
32
 
33
33
  class SearchQuery(BaseModel):
34
- """Standardized search query structure. At least 1 search criterion is required."""
34
+ """
35
+ Standardized search query structure. At least 1 search criterion is required.
36
+ """
35
37
 
36
38
  text: str | None = None
37
39
  """String to match against using in a semantic search, i.e. using vector distance."""
38
40
  keywords: list[str] = []
39
41
  """List of keywords to **exact-match** in a keyword search."""
40
- metadata_filters: list[MetadataFilter] = []
41
- """List of metadata filter conditions that must be matched."""
42
+ metadata_filters: list[MetadataFilter] = Field(
43
+ default=[],
44
+ json_schema_extra={"metadata_schema": BaseDocumentMetadata.model_json_schema()},
45
+ )
46
+ """
47
+ List of metadata conditions that must be matched.
48
+ Refer to `metadata_schema` for the expected schema, as it exists in the database.
49
+ """
42
50
  date_range: tuple[datetime, datetime] | None = None
43
51
  """Retrieve/limit results based on created_at & updated_at timestamps (i.e. database operations)"""
44
52
  limit: int = Field(
@@ -47,7 +55,10 @@ class SearchQuery(BaseModel):
47
55
  )
48
56
  """Maximum number of results to return."""
49
57
 
50
- model_config = ConfigDict(use_attribute_docstrings=True)
58
+ model_config = ConfigDict(
59
+ use_attribute_docstrings=True,
60
+ arbitrary_types_allowed=True,
61
+ )
51
62
 
52
63
  @model_validator(mode="after")
53
64
  def ensure_criterion(self):
@@ -4,4 +4,4 @@ Service layer for document operations.
4
4
 
5
5
  from pgvector_template.service.document_service import DocumentService, DocumentServiceConfig
6
6
 
7
- __all__ = ["DocumentService", "DocumentServiceConfig"]
7
+ __all__ = ["DocumentService", "DocumentServiceConfig"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pgvector-template
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Template library for flexible PGVector RAG implementations
5
5
  Author-email: DL <v49t9zpqd@mozmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pgvector-template"
7
- version = "0.3.0"
7
+ version = "0.3.2"
8
8
  description = "Template library for flexible PGVector RAG implementations"
9
9
  authors = [{ name="DL", email="v49t9zpqd@mozmail.com" }]
10
10
  license = { text = "MIT" }