goodmem-nlweb 0.3.0__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.
- goodmem_nlweb-0.3.0/.gitignore +21 -0
- goodmem_nlweb-0.3.0/CHANGELOG.md +194 -0
- goodmem_nlweb-0.3.0/LICENSE +201 -0
- goodmem_nlweb-0.3.0/PKG-INFO +232 -0
- goodmem_nlweb-0.3.0/README.md +200 -0
- goodmem_nlweb-0.3.0/pyproject.toml +90 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/__init__.py +40 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/_connection.py +70 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/_ids.py +56 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/_results.py +110 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/_schema.py +135 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/_spaces.py +124 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/_typing.py +49 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/filters.py +138 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/provider.py +424 -0
- goodmem_nlweb-0.3.0/src/goodmem_nlweb/py.typed +0 -0
- goodmem_nlweb-0.3.0/tests/__init__.py +0 -0
- goodmem_nlweb-0.3.0/tests/conftest.py +77 -0
- goodmem_nlweb-0.3.0/tests/fixtures/memories_list.json +65 -0
- goodmem_nlweb-0.3.0/tests/fixtures/retrieve_all.ndjson +8 -0
- goodmem_nlweb-0.3.0/tests/fixtures/retrieve_broken_reranker.ndjson +9 -0
- goodmem_nlweb-0.3.0/tests/fixtures/retrieve_empty.ndjson +2 -0
- goodmem_nlweb-0.3.0/tests/fixtures/retrieve_site.ndjson +6 -0
- goodmem_nlweb-0.3.0/tests/fixtures/space.json +4 -0
- goodmem_nlweb-0.3.0/tests/test_config.py +166 -0
- goodmem_nlweb-0.3.0/tests/test_e2e.py +208 -0
- goodmem_nlweb-0.3.0/tests/test_filters.py +202 -0
- goodmem_nlweb-0.3.0/tests/test_ids.py +451 -0
- goodmem_nlweb-0.3.0/tests/test_regressions.py +341 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
.eggs/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.tox/
|
|
9
|
+
.venv/
|
|
10
|
+
.env
|
|
11
|
+
.coverage
|
|
12
|
+
htmlcov/
|
|
13
|
+
.mypy_cache/
|
|
14
|
+
.ruff_cache/
|
|
15
|
+
.DS_Store
|
|
16
|
+
.venv/
|
|
17
|
+
.venv-smoke/
|
|
18
|
+
.ruff_cache/
|
|
19
|
+
.mypy_cache/
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
dist/
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
Renamed to `goodmem-nlweb` (import `goodmem_nlweb`), the goodmem-<framework>
|
|
8
|
+
naming used by goodmem-adk and goodmem-semantic-kernel. Breaking: update
|
|
9
|
+
imports from `nlweb_goodmem` to `goodmem_nlweb`, and NLWeb provider entries
|
|
10
|
+
from `import_path: nlweb_goodmem` to `import_path: goodmem_nlweb`.
|
|
11
|
+
|
|
12
|
+
## 0.2.2
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
**`metadata_filter` values are compared under the cast their type calls
|
|
17
|
+
for.** `search(..., metadata_filter={...})` turned every value into
|
|
18
|
+
`str(value)` and compared it as `TEXT`. GoodMem answers a comparison under the
|
|
19
|
+
wrong cast with HTTP 200 and no results, so a boolean filter looked exactly
|
|
20
|
+
like "nothing stored". Now `bool` is compared as `BOOLEAN` (checked before
|
|
21
|
+
`int`, which it subclasses), `int`/`float` as `NUMERIC` (plain decimals), and
|
|
22
|
+
`str` as `TEXT` with the same escaping as before. `None`, non-finite numbers
|
|
23
|
+
and any other type raise `ValueError` before a request is made.
|
|
24
|
+
|
|
25
|
+
Measured against a live server (v1.0.320) through `search()`, in a space
|
|
26
|
+
holding `amman` (`{"flag": true, "n": 5, "category": "x"}`), `petra`
|
|
27
|
+
(`{"flag": false, "n": 3, "category": "y"}`) and a memory with neither:
|
|
28
|
+
|
|
29
|
+
| `metadata_filter` | 0.2.1 sent → matched | 0.2.2 sent → matched |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `{"flag": True}` | `CAST(val('$.flag') AS TEXT) = 'True'` → nothing | `CAST(val('$.flag') AS BOOLEAN) = true` → `amman` |
|
|
32
|
+
| `{"flag": False}` | `… AS TEXT) = 'False'` → nothing | `… AS BOOLEAN) = false` → `petra` |
|
|
33
|
+
| `{"n": 5.0}` | `CAST(val('$.n') AS TEXT) = '5.0'` → nothing | `CAST(val('$.n') AS NUMERIC) = 5.0` → `amman` |
|
|
34
|
+
| `{"n": 5}` | `… AS TEXT) = '5'` → `amman` (the text of a stored 5 happens to be `'5'`) | `… AS NUMERIC) = 5` → `amman` |
|
|
35
|
+
| `{"flag": True, "n": 5, "category": "x"}` (as `yaml.safe_load` gives it) | nothing | `amman` |
|
|
36
|
+
| `{"flag": None}` | `… AS TEXT) = 'None'` → nothing | `ValueError`; no request |
|
|
37
|
+
| `{"n": float("nan")}`, `{"tags": ["a", "b"]}` | sent as `'nan'`, `'[\'a\', \'b\']'` (recorded over the mock transport) | `ValueError`; no request |
|
|
38
|
+
| `{"category": "x"}`, `{"quote": "it's"}`, `{"bs": "a\\b"}` | `TEXT`, escaped → `amman` | unchanged |
|
|
39
|
+
| `{"flag": "true"}` (a string) | `… AS TEXT) = 'true'` → nothing | unchanged: a string is text |
|
|
40
|
+
|
|
41
|
+
The README documents the rule under "Metadata filters", including how a
|
|
42
|
+
filter read from YAML is typed (`true` is a bool, `"true"` a string) and that
|
|
43
|
+
`metadata_filter` is a `search()` argument: a `metadata_filter:` key in the
|
|
44
|
+
provider's NLWeb entry is ignored.
|
|
45
|
+
|
|
46
|
+
### Tests
|
|
47
|
+
|
|
48
|
+
- 194 offline tests (was 159). `tests/test_filters.py` (34) drives
|
|
49
|
+
`search()` through the real SDK over a mock transport and asserts on the
|
|
50
|
+
filter that reaches the wire, including the README's table, Python example
|
|
51
|
+
and YAML block; 25 of them fail on 0.2.1 (the other 9 are string, empty and
|
|
52
|
+
control-character controls that must not change). `tests/test_config.py`
|
|
53
|
+
adds one test that a `metadata_filter:` key in the provider entry sends no
|
|
54
|
+
filter.
|
|
55
|
+
- 22 live tests (was 13): the fixture adds a memory with typed metadata, and
|
|
56
|
+
9 tests filter on it by bool, int, float, text and all three together, and
|
|
57
|
+
check that `False`, `4`, `"true"` and `"y"` exclude it. On 0.2.1 the bool,
|
|
58
|
+
float and combined filters fail.
|
|
59
|
+
|
|
60
|
+
## 0.2.1
|
|
61
|
+
|
|
62
|
+
### Security
|
|
63
|
+
|
|
64
|
+
**An id is refused unless it is a UUID, before any request is made.** The
|
|
65
|
+
`goodmem` SDK (0.1.35) builds request paths by interpolating ids unencoded
|
|
66
|
+
(`f"/v1/spaces/{space_id}/memories"`, `f"/v1/memories/{id}"`) and httpx
|
|
67
|
+
resolves dot segments before it sends, so an id could steer a request to a
|
|
68
|
+
different endpoint. Every GoodMem id is a UUID, so one validator,
|
|
69
|
+
`nlweb_goodmem._ids.require_uuid`, accepts a canonical UUID (lowercased, or a
|
|
70
|
+
`uuid.UUID`) and refuses everything else with `ValueError`.
|
|
71
|
+
|
|
72
|
+
Measured against a local HTTP server that records each request line as it
|
|
73
|
+
arrives (`<U>` is a well-formed UUID):
|
|
74
|
+
|
|
75
|
+
| Input | 0.2.0 sent | 0.2.1 |
|
|
76
|
+
| --- | --- | --- |
|
|
77
|
+
| `space_id="../spaces/<U>"`, then `get_sites()` | `GET /v1/spaces/<U>/memories` — another space's memories | `ValueError` naming `space_id`; nothing sent |
|
|
78
|
+
| the same, then `GoodMemObjectLookupProvider.get_by_id(url)` | `GET /v1/spaces/<U>/memories?filter=…` | refused; nothing sent |
|
|
79
|
+
| `space_id="<U>#frag"`, then `get_sites()` | `GET /v1/spaces/<U>` — the space record, not its memories | refused; nothing sent |
|
|
80
|
+
| `space_id="<U>?x=1"`, then `get_by_id(url)` | `GET /v1/spaces/<U>?filter=…` | refused; nothing sent |
|
|
81
|
+
| `space_id="../spaces/<U>"`, then `search()` or `upload_documents()` | the value, in the request body | refused; nothing sent |
|
|
82
|
+
| a space id the server returns for `space_name` | used in the path unchecked | checked before every request |
|
|
83
|
+
| a memory id in a batch-create response, polled by `upload_documents(wait=True)` | `"../spaces/<U>"` became `GET /v1/spaces/<U>` | `GoodMemUploadError` carrying the created ids; no poll |
|
|
84
|
+
| `reranker_id` or `embedder_id` that is not a UUID | the value, in the request body | refused; nothing sent |
|
|
85
|
+
|
|
86
|
+
The same holds for `a/../../spaces/<U>`, `%2e%2e/spaces/<U>`,
|
|
87
|
+
`..%2Fspaces%2F<U>`, `<U>/../../spaces/<U>`, `""`, `" <U>"` and `"<U>\n"`.
|
|
88
|
+
Configured ids are checked when the provider is built, so a bad option fails
|
|
89
|
+
when NLWeb loads it; the space id is checked again right before each request.
|
|
90
|
+
|
|
91
|
+
`get_by_id(object_id)` is the entry point NLWeb feeds from a web request.
|
|
92
|
+
That id is the item's URL, not a GoodMem id, and it already travelled only
|
|
93
|
+
as an escaped literal inside the `filter` query parameter. It is not
|
|
94
|
+
required to be a UUID; tests now pin that every payload above, and
|
|
95
|
+
`<U>&max_results=500`, leaves the path at `/v1/spaces/<configured>/memories`
|
|
96
|
+
with exactly one query parameter.
|
|
97
|
+
|
|
98
|
+
### Fixed
|
|
99
|
+
|
|
100
|
+
- **The documented NLWeb configuration now loads.** The README, the package
|
|
101
|
+
docstring and `GoodMemRetrievalProvider`'s docstring nested the options
|
|
102
|
+
under `options:`. nlweb-core 0.7 passes every key beside `import_path` and
|
|
103
|
+
`class_name` to the constructor, so the provider received one
|
|
104
|
+
`options={...}` keyword and NLWeb's startup failed with `ValueError:
|
|
105
|
+
GoodMemRetrievalProvider needs space_id or space_name`. The options now sit
|
|
106
|
+
beside `class_name`.
|
|
107
|
+
- **The documented entry is named `default`.** It was `goodmem`, but
|
|
108
|
+
nlweb-core's `ask` handler calls `get_retrieval_provider("default")`; with
|
|
109
|
+
only a `goodmem` entry that raised `Retrieval provider 'default' is not
|
|
110
|
+
configured`, and alongside another `default` it was loaded and never used.
|
|
111
|
+
- The README shows the `object_storage` entry for
|
|
112
|
+
`GoodMemObjectLookupProvider` (NLWeb only enriches results when one named
|
|
113
|
+
`default` exists), mentions `_env` keys such as `api_key_env`, and says that
|
|
114
|
+
an empty `embedder_id`/`reranker_id` means "not set".
|
|
115
|
+
|
|
116
|
+
### Changed
|
|
117
|
+
|
|
118
|
+
- An empty `space_id` raises `space_id must be a UUID`. With `space_name`
|
|
119
|
+
also set, 0.2.0 used the empty id instead of resolving the name. An empty
|
|
120
|
+
`embedder_id` or `reranker_id` still means "not set".
|
|
121
|
+
- An uppercase id is sent lowercased, and a `uuid.UUID` is accepted (0.2.0's
|
|
122
|
+
`search()` and `upload_documents()` raised on one).
|
|
123
|
+
- 159 offline tests (was 34): 119 in `tests/test_ids.py` drive the real SDK
|
|
124
|
+
over a socket, and 6 in `tests/test_config.py` load the documented YAML
|
|
125
|
+
with nlweb-core's own loader. Tests that used placeholder ids (`"emb-1"`, `"bogus"`,
|
|
126
|
+
`"rr"`, `"not-a-uuid"`, `"other-id"`) now use UUIDs; the broken-reranker
|
|
127
|
+
test uses the all-zero id its fixture was recorded with.
|
|
128
|
+
|
|
129
|
+
## 0.2.0
|
|
130
|
+
|
|
131
|
+
A rewrite. 0.1.0 shipped no NLWeb integration: it was fourteen classes
|
|
132
|
+
wrapping REST endpoints with `httpx`, and `nlweb` was never imported and was
|
|
133
|
+
not a dependency. It was the same template as `deepeval-goodmem` 0.1.0 — after
|
|
134
|
+
normalising names, `_client.py` differed by 16 lines out of 683.
|
|
135
|
+
|
|
136
|
+
0.2.0 implements NLWeb's actual provider interfaces, on the official `goodmem`
|
|
137
|
+
SDK.
|
|
138
|
+
|
|
139
|
+
### Added
|
|
140
|
+
|
|
141
|
+
- **`GoodMemRetrievalProvider`** — a real `nlweb_core.retriever.RetrievalProvider`.
|
|
142
|
+
Registered purely by configuration (`import_path` / `class_name` / `options`),
|
|
143
|
+
so it never has to be added to NLWeb's source tree.
|
|
144
|
+
- **Site filtering** — NLWeb's core requirement. Sites are memory metadata,
|
|
145
|
+
filtered server-side with escaped expressions. One site, several sites
|
|
146
|
+
(OR-ed), or `"all"`.
|
|
147
|
+
- **`GoodMemObjectLookupProvider`** — `ObjectLookupProvider.get_by_id(url)`,
|
|
148
|
+
so NLWeb can enrich a result with the full Schema.org object.
|
|
149
|
+
- **`upload_documents()`** and the Schema.org mapping in `nlweb_goodmem._schema`.
|
|
150
|
+
- **`get_sites()`** — the distinct sites present in a space.
|
|
151
|
+
- 34 offline tests over captured server bytes and 13 live tests with verified
|
|
152
|
+
teardown. 0.1.0 had 10 tests that passed against every defect below, and no
|
|
153
|
+
workflow ever ran them.
|
|
154
|
+
|
|
155
|
+
### Fixed
|
|
156
|
+
|
|
157
|
+
Every defect was reproduced against a live server (v1.0.320) first.
|
|
158
|
+
|
|
159
|
+
| Behaviour | 0.1.0 | 0.2.0 |
|
|
160
|
+
| --- | --- | --- |
|
|
161
|
+
| Retrieval statuses | The NDJSON parser had branches for boundaries, memories, abstract replies and items — and **none for `status`**. A bogus reranker made the server send three status events; all were dropped and the call reported success | Classified per the retrieval status contract: informational notices ignored, real problems logged, unknown codes surfaced as `UNKNOWN` |
|
|
162
|
+
| A retrieval that failed outright | `success: true, totalResults: 0` with a message blaming indexing | Empty list plus a `UserWarning`; never raised into an `ask` request |
|
|
163
|
+
| Searching when nothing matches | Up to **12 re-POSTs** over 60s (`wait_for_indexing=True`, `poll_interval=5`), re-invoking the LLM each time when `llm_id` was set | One request |
|
|
164
|
+
| Relevance scores | Documented as "0-1"; live values are negative for vector and a different scale for reranker | Not exposed: `RetrievedItem` has no score field, and server order is preserved |
|
|
165
|
+
| `metadata_filter` | A raw string pasted into the request | Escaped; a site containing a quote matches nothing rather than everything |
|
|
166
|
+
| Any error | `run()` caught **everything** and returned `{"success": false, "error": "…check developer.mozilla.org"}` as a string, discarding the server's reason | Errors propagate with the server's message |
|
|
167
|
+
| `update_space(public_read=…)` | HTTP 400 — the field was removed from the API | Gone |
|
|
168
|
+
| Batch ingest | n/a | Per-item `success` is checked: the server returns HTTP 200 even when an item failed |
|
|
169
|
+
| API key | A plain attribute on every operation object | Held on a private connection |
|
|
170
|
+
|
|
171
|
+
### Migration
|
|
172
|
+
|
|
173
|
+
The fourteen `GoodMem*` operation classes are gone; they were a REST client,
|
|
174
|
+
and the `goodmem` SDK does that job better.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
# 0.1.0
|
|
178
|
+
from nlweb_goodmem import GoodMemRetrieveMemories
|
|
179
|
+
out = json.loads(GoodMemRetrieveMemories(...).run(query="…", space_ids=sid))
|
|
180
|
+
|
|
181
|
+
# 0.2.0 — through NLWeb
|
|
182
|
+
provider = GoodMemRetrievalProvider(space_name="nlweb", base_url=…, api_key=…)
|
|
183
|
+
items = await provider.search("…", "example.com")
|
|
184
|
+
|
|
185
|
+
# 0.2.0 — for plain API access, use the SDK
|
|
186
|
+
from goodmem import AsyncGoodmem
|
|
187
|
+
await AsyncGoodmem(base_url=…, api_key=…).spaces.create(...)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Python 3.9 is no longer supported; 3.10+ is required.
|
|
191
|
+
|
|
192
|
+
## 0.1.0
|
|
193
|
+
|
|
194
|
+
Initial release.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 GoodMem
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: goodmem-nlweb
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: GoodMem as an NLWeb retrieval provider — Schema.org retrieval, site filtering, and object lookup.
|
|
5
|
+
Project-URL: homepage, https://github.com/PAIR-Systems-Inc/goodmem_nlweb
|
|
6
|
+
Project-URL: source, https://github.com/PAIR-Systems-Inc/goodmem_nlweb
|
|
7
|
+
Project-URL: issues, https://github.com/PAIR-Systems-Inc/goodmem_nlweb/issues
|
|
8
|
+
Author-email: GoodMem <support@goodmem.ai>
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: goodmem,nlweb,rag,retrieval,schema.org,vector-search
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: goodmem>=0.1.34
|
|
23
|
+
Requires-Dist: nlweb-core>=0.7
|
|
24
|
+
Requires-Dist: typing-extensions>=4.7
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
27
|
+
Requires-Dist: mypy==1.18.2; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff==0.16.8; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# goodmem-nlweb
|
|
34
|
+
|
|
35
|
+
GoodMem as an [NLWeb](https://github.com/nlweb-ai/NLWeb) retrieval provider.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install goodmem-nlweb
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configure
|
|
42
|
+
|
|
43
|
+
NLWeb imports a provider by path, so this package never has to be added to
|
|
44
|
+
NLWeb's own source tree:
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
retrieval:
|
|
48
|
+
default:
|
|
49
|
+
import_path: goodmem_nlweb
|
|
50
|
+
class_name: GoodMemRetrievalProvider
|
|
51
|
+
base_url: https://localhost:8080
|
|
52
|
+
api_key: gm_…
|
|
53
|
+
space_name: nlweb
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
NLWeb's `ask` handler asks for the retrieval provider named `default`, so
|
|
57
|
+
that is the name to give it. Options sit beside `import_path` and
|
|
58
|
+
`class_name`: NLWeb passes every other key of the entry to the constructor as
|
|
59
|
+
a keyword argument. A key ending in `_env` is read from the environment
|
|
60
|
+
instead, so `api_key_env: GOODMEM_API_KEY` keeps the key out of the file.
|
|
61
|
+
|
|
62
|
+
It implements `nlweb_core.retriever.RetrievalProvider`, so `search()` returns
|
|
63
|
+
real `RetrievedItem` objects and `close()` releases the client.
|
|
64
|
+
|
|
65
|
+
`space_id`, `embedder_id` and `reranker_id` must be GoodMem ids, which are
|
|
66
|
+
UUIDs; any other value raises `ValueError` when the provider is built, before
|
|
67
|
+
a request is made. (An empty `embedder_id` or `reranker_id` means "not set";
|
|
68
|
+
an empty `space_id` is refused.) The GoodMem SDK places ids in the URL path
|
|
69
|
+
unencoded, so a value like `../spaces/<id>` would otherwise send the request to
|
|
70
|
+
a different endpoint.
|
|
71
|
+
|
|
72
|
+
## Sites
|
|
73
|
+
|
|
74
|
+
NLWeb filters every call by *site*; GoodMem has no such concept. A site is
|
|
75
|
+
stored as memory metadata and filtered **server-side** with GoodMem's filter
|
|
76
|
+
grammar, the same way NLWeb's own Qdrant provider uses a `site` payload field.
|
|
77
|
+
Values are escaped, never interpolated — a site called `x' OR '1'='1` matches
|
|
78
|
+
nothing rather than everything.
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
await provider.search("noodle soup", "recipes.example.com") # one site
|
|
82
|
+
await provider.search("noodle soup", ["a.com", "b.com"]) # OR across sites
|
|
83
|
+
await provider.search("noodle soup", "all") # every site
|
|
84
|
+
await provider.search_all_sites("noodle soup") # same thing
|
|
85
|
+
await provider.get_sites() # ['a.com', 'b.com']
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Metadata filters
|
|
89
|
+
|
|
90
|
+
`search()` also takes `metadata_filter`, a mapping of metadata field to
|
|
91
|
+
value. Each pair becomes a server-side equality, AND-ed with the others and
|
|
92
|
+
with the site filter. GoodMem stores metadata as JSON and compares it under an
|
|
93
|
+
explicit cast, and a comparison under the wrong cast is accepted and matches
|
|
94
|
+
nothing, so each value is cast by its Python type:
|
|
95
|
+
|
|
96
|
+
| Value | Compared as | Sent to the server |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| `str` | text | `CAST(val('$.cuisine') AS TEXT) = 'Malaysian'` |
|
|
99
|
+
| `bool` | boolean | `CAST(val('$.vegetarian') AS BOOLEAN) = true` |
|
|
100
|
+
| `int`, `float` | number | `CAST(val('$.servings') AS NUMERIC) = 4` |
|
|
101
|
+
|
|
102
|
+
`None`, `nan`, `inf` and any other type (a list, a dict, …) raise
|
|
103
|
+
`ValueError` before a request is made. Text is escaped exactly as a site is.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
await provider.search("noodle soup", "recipes.example.com",
|
|
107
|
+
metadata_filter={"vegetarian": True, "servings": 4})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
A filter read from YAML (or JSON) keeps the type the loader gives it, so write
|
|
111
|
+
each value the way it is stored: `vegetarian: true` is a boolean, while
|
|
112
|
+
`vegetarian: "true"` is the string `"true"` and matches only a stored string.
|
|
113
|
+
|
|
114
|
+
```yaml
|
|
115
|
+
vegetarian: true
|
|
116
|
+
servings: 4
|
|
117
|
+
cuisine: Malaysian
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`metadata_filter` is an argument to `search()`, not a provider option: NLWeb's
|
|
121
|
+
`ask` handler does not pass one, and a `metadata_filter:` key in the
|
|
122
|
+
provider's YAML entry is ignored.
|
|
123
|
+
|
|
124
|
+
## Ingesting Schema.org documents
|
|
125
|
+
|
|
126
|
+
`RetrievalProvider` only reads, so ingestion is a helper rather than part of
|
|
127
|
+
the interface:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from goodmem_nlweb import GoodMemRetrievalProvider, upload_documents
|
|
131
|
+
|
|
132
|
+
provider = GoodMemRetrievalProvider(space_name="nlweb", base_url=…, api_key=…)
|
|
133
|
+
await upload_documents(provider, [
|
|
134
|
+
{"@type": "Recipe", "url": "https://ex.com/r/laksa", "name": "Singapore Laksa",
|
|
135
|
+
"description": "A coconut curry noodle soup."},
|
|
136
|
+
], site="recipes.example.com")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| NLWeb | GoodMem |
|
|
140
|
+
| --- | --- |
|
|
141
|
+
| `url` | `metadata["url"]` — the item's identity, and what NLWeb dedupes on |
|
|
142
|
+
| `site` | `metadata["site"]` — what every search filters on |
|
|
143
|
+
| `raw_schema_object` | `metadata["schema_json"]` |
|
|
144
|
+
| (text to embed) | the memory's content |
|
|
145
|
+
|
|
146
|
+
The embedded text is **not** the raw JSON. Embedding a JSON blob buries the
|
|
147
|
+
words a query would match under punctuation and key names, so the text is
|
|
148
|
+
extracted from `name`, `headline`, `description`, `articleBody` and friends,
|
|
149
|
+
and the untouched object is kept alongside for NLWeb to return verbatim.
|
|
150
|
+
|
|
151
|
+
`upload_documents` inspects every item of the batch response: the server
|
|
152
|
+
returns HTTP 200 even when an item failed, so per-item `success` is the only
|
|
153
|
+
signal. A partial failure raises `GoodMemUploadError` carrying the ids that
|
|
154
|
+
did land.
|
|
155
|
+
|
|
156
|
+
## Looking objects up by URL
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from goodmem_nlweb import GoodMemObjectLookupProvider
|
|
160
|
+
|
|
161
|
+
lookup = GoodMemObjectLookupProvider(space_name="nlweb", base_url=…, api_key=…)
|
|
162
|
+
await lookup.get_by_id("https://ex.com/r/laksa") # the full Schema.org object
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Implements `ObjectLookupProvider`, so NLWeb can enrich a truncated search
|
|
166
|
+
result with the complete object without a second datastore. NLWeb does that
|
|
167
|
+
when an `object_storage` provider named `default` is configured:
|
|
168
|
+
|
|
169
|
+
```yaml
|
|
170
|
+
object_storage:
|
|
171
|
+
default:
|
|
172
|
+
import_path: goodmem_nlweb
|
|
173
|
+
class_name: GoodMemObjectLookupProvider
|
|
174
|
+
base_url: https://localhost:8080
|
|
175
|
+
api_key: gm_…
|
|
176
|
+
space_name: nlweb
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The id NLWeb passes here comes from a web request. It is the item's URL, not
|
|
180
|
+
a GoodMem id, so it is not required to be a UUID: it only ever travels as an
|
|
181
|
+
escaped value in the `filter` query parameter, never in the URL path.
|
|
182
|
+
|
|
183
|
+
## Scores, and why there are none
|
|
184
|
+
|
|
185
|
+
A GoodMem vector score is a negative inner product — the best match is the
|
|
186
|
+
*lowest* number — and a reranker score is a different scale that also goes
|
|
187
|
+
negative. `RetrievedItem` has no score field, and inventing one would imply a
|
|
188
|
+
comparability that does not hold. Results keep the server's ordering, which is
|
|
189
|
+
authoritative, and are never re-sorted here.
|
|
190
|
+
|
|
191
|
+
## Degraded retrieval
|
|
192
|
+
|
|
193
|
+
If the server reports a problem, whatever it did return is still returned and
|
|
194
|
+
the statuses are logged. If it reports a problem *and* returns nothing, the
|
|
195
|
+
result is an empty list plus a `UserWarning` — never an exception, because an
|
|
196
|
+
exception here would take down an `ask` request that could still answer from
|
|
197
|
+
another endpoint. Notices that carry no loss (`FEATURE_DISABLED`,
|
|
198
|
+
`LLM_CAPABILITY_INFERRED`) are ignored; a status code this version does not
|
|
199
|
+
know is reported as `UNKNOWN` rather than dropped.
|
|
200
|
+
|
|
201
|
+
## Which NLWeb?
|
|
202
|
+
|
|
203
|
+
This targets **`nlweb-core`** (the pip-installable package with the
|
|
204
|
+
config-driven provider architecture). The `nlweb-ai/NLWeb` reference
|
|
205
|
+
implementation has a different interface (`VectorDBClientInterface`, returning
|
|
206
|
+
`list[list[str]]`) and a hardcoded provider table, so a third-party package
|
|
207
|
+
cannot register with it — that one needs an upstream PR.
|
|
208
|
+
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
pip install -e ".[dev]"
|
|
213
|
+
ruff check src tests examples && mypy && pytest -m "not integration"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The offline suite replays NDJSON captured from a live GoodMem server
|
|
217
|
+
(v1.0.320) through the real SDK decoders. The live suite needs a server:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
GOODMEM_BASE_URL=… GOODMEM_API_KEY=… GOODMEM_EMBEDDER_ID=… \
|
|
221
|
+
GOODMEM_RERANKER_ID=… GOODMEM_VERIFY_SSL=0 \
|
|
222
|
+
pytest -m integration
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
`GOODMEM_RERANKER_ID` is optional — the reranker test skips without it.
|
|
226
|
+
`GOODMEM_VERIFY_SSL=0` is for a local server with a self-signed certificate.
|
|
227
|
+
|
|
228
|
+
There is no default credential anywhere in this repository.
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
MIT
|