langchain-antfly 0.1.0rc1__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.
- langchain_antfly-0.1.0rc1/.gitignore +12 -0
- langchain_antfly-0.1.0rc1/LICENSE +202 -0
- langchain_antfly-0.1.0rc1/PKG-INFO +98 -0
- langchain_antfly-0.1.0rc1/README.md +74 -0
- langchain_antfly-0.1.0rc1/pyproject.toml +30 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/__init__.py +33 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/_utils.py +178 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/embeddings.py +162 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/graphs.py +653 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/py.typed +0 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/rerankers.py +82 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/retrievers.py +107 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/stores.py +221 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/tools.py +32 -0
- langchain_antfly-0.1.0rc1/src/langchain_antfly/vectorstores.py +589 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Antfly Contributors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-antfly
|
|
3
|
+
Version: 0.1.0rc1
|
|
4
|
+
Summary: Persistent retrieval, inference, documents and graphs for LangChain with Antfly
|
|
5
|
+
Project-URL: Homepage, https://github.com/antflydb/langchain-antfly
|
|
6
|
+
Project-URL: Repository, https://github.com/antflydb/langchain-antfly
|
|
7
|
+
Project-URL: Documentation, https://github.com/antflydb/langchain-antfly#readme
|
|
8
|
+
Project-URL: Issues, https://github.com/antflydb/langchain-antfly/issues
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: antfly,langchain,multimodal,rag,vector-search
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: antfly-sdk<0.3,>=0.2.1
|
|
19
|
+
Requires-Dist: langchain-core<2,>=1.0
|
|
20
|
+
Requires-Dist: numpy>=1.26
|
|
21
|
+
Provides-Extra: graph
|
|
22
|
+
Requires-Dist: langchain-community<1,>=0.4; extra == 'graph'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# Antfly for LangChain
|
|
26
|
+
|
|
27
|
+
Persistent vector and hybrid retrieval, text/image embeddings, reranking,
|
|
28
|
+
document and media storage, and graph context backed by an Antfly server.
|
|
29
|
+
Python 3.11 or newer. Apache-2.0 licensed.
|
|
30
|
+
|
|
31
|
+
**Release candidate:** `0.1.0rc1`. Requires `antfly-sdk>=0.2.1` and a compatible
|
|
32
|
+
Antfly server; `0.3.0-rc.5` is the tested baseline. See the
|
|
33
|
+
[server setup](https://github.com/antflydb/langchain-antfly#first-result).
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install langchain-antfly==0.1.0rc1
|
|
39
|
+
# Optional GraphDocument ingestion and graph tools:
|
|
40
|
+
pip install 'langchain-antfly[graph]==0.1.0rc1'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The package connects to an existing Antfly server; it does not install or start
|
|
44
|
+
one. Configure a compatible server with inference enabled and choose an installed
|
|
45
|
+
embedding model using the [setup guide](https://github.com/antflydb/langchain-antfly#first-result).
|
|
46
|
+
Models are not downloaded automatically.
|
|
47
|
+
|
|
48
|
+
## Retrieve three documents
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import os
|
|
52
|
+
|
|
53
|
+
from antfly import AntflyClient
|
|
54
|
+
from langchain_antfly import AntflyEmbeddings, AntflyVectorStore
|
|
55
|
+
from langchain_core.documents import Document
|
|
56
|
+
|
|
57
|
+
with AntflyClient(
|
|
58
|
+
base_url=os.environ["ANTFLY_URL"], token=os.getenv("ANTFLY_TOKEN")
|
|
59
|
+
) as client:
|
|
60
|
+
embeddings = AntflyEmbeddings(
|
|
61
|
+
client=client, model=os.environ["ANTFLY_EMBEDDING_MODEL"]
|
|
62
|
+
)
|
|
63
|
+
store = AntflyVectorStore.from_documents(
|
|
64
|
+
[
|
|
65
|
+
Document(id="owner", page_content="Mira Chen owns operations."),
|
|
66
|
+
Document(id="target", page_content="The shipment target is 120 crates."),
|
|
67
|
+
Document(id="storage", page_content="Apples are stored in the cool warehouse."),
|
|
68
|
+
],
|
|
69
|
+
embeddings,
|
|
70
|
+
client=client,
|
|
71
|
+
table="langchain_example",
|
|
72
|
+
distance_metric="cosine",
|
|
73
|
+
)
|
|
74
|
+
documents = store.as_retriever(search_kwargs={"k": 1}).invoke(
|
|
75
|
+
"Who owns operations?"
|
|
76
|
+
)
|
|
77
|
+
print(documents[0].page_content)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The factory creates a missing table or reuses a compatible one. Stable document
|
|
81
|
+
IDs make repeated writes update the same records. To attach without writing,
|
|
82
|
+
construct `AntflyVectorStore(client=client, table="langchain_example", embedding=embeddings)`.
|
|
83
|
+
Delete this example's dedicated table with `client.drop_table("langchain_example")`
|
|
84
|
+
inside the client context when finished. Async factories, retrieval and mutations
|
|
85
|
+
are also available.
|
|
86
|
+
|
|
87
|
+
## More examples
|
|
88
|
+
|
|
89
|
+
- [Persistent PDF and image RAG](https://github.com/antflydb/langchain-antfly/tree/main/examples/multimodal):
|
|
90
|
+
extract text and images, retrieve persistent parents and original media, and
|
|
91
|
+
generate answers with an existing vision provider.
|
|
92
|
+
- [Hybrid search, reranking, graph context and caching](https://github.com/antflydb/langchain-antfly/blob/main/docs/recipes.md).
|
|
93
|
+
- [API reference and limitations](https://github.com/antflydb/langchain-antfly/blob/main/docs/api-reference.md).
|
|
94
|
+
- [Validation evidence](https://github.com/antflydb/langchain-antfly/blob/main/docs/validation-report.md).
|
|
95
|
+
|
|
96
|
+
Persistent LangGraph agent memory is available separately in
|
|
97
|
+
`langgraph-store-antfly`. This package does not include a chat-model adapter or
|
|
98
|
+
an execution checkpointer.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Antfly for LangChain
|
|
2
|
+
|
|
3
|
+
Persistent vector and hybrid retrieval, text/image embeddings, reranking,
|
|
4
|
+
document and media storage, and graph context backed by an Antfly server.
|
|
5
|
+
Python 3.11 or newer. Apache-2.0 licensed.
|
|
6
|
+
|
|
7
|
+
**Release candidate:** `0.1.0rc1`. Requires `antfly-sdk>=0.2.1` and a compatible
|
|
8
|
+
Antfly server; `0.3.0-rc.5` is the tested baseline. See the
|
|
9
|
+
[server setup](https://github.com/antflydb/langchain-antfly#first-result).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install langchain-antfly==0.1.0rc1
|
|
15
|
+
# Optional GraphDocument ingestion and graph tools:
|
|
16
|
+
pip install 'langchain-antfly[graph]==0.1.0rc1'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The package connects to an existing Antfly server; it does not install or start
|
|
20
|
+
one. Configure a compatible server with inference enabled and choose an installed
|
|
21
|
+
embedding model using the [setup guide](https://github.com/antflydb/langchain-antfly#first-result).
|
|
22
|
+
Models are not downloaded automatically.
|
|
23
|
+
|
|
24
|
+
## Retrieve three documents
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import os
|
|
28
|
+
|
|
29
|
+
from antfly import AntflyClient
|
|
30
|
+
from langchain_antfly import AntflyEmbeddings, AntflyVectorStore
|
|
31
|
+
from langchain_core.documents import Document
|
|
32
|
+
|
|
33
|
+
with AntflyClient(
|
|
34
|
+
base_url=os.environ["ANTFLY_URL"], token=os.getenv("ANTFLY_TOKEN")
|
|
35
|
+
) as client:
|
|
36
|
+
embeddings = AntflyEmbeddings(
|
|
37
|
+
client=client, model=os.environ["ANTFLY_EMBEDDING_MODEL"]
|
|
38
|
+
)
|
|
39
|
+
store = AntflyVectorStore.from_documents(
|
|
40
|
+
[
|
|
41
|
+
Document(id="owner", page_content="Mira Chen owns operations."),
|
|
42
|
+
Document(id="target", page_content="The shipment target is 120 crates."),
|
|
43
|
+
Document(id="storage", page_content="Apples are stored in the cool warehouse."),
|
|
44
|
+
],
|
|
45
|
+
embeddings,
|
|
46
|
+
client=client,
|
|
47
|
+
table="langchain_example",
|
|
48
|
+
distance_metric="cosine",
|
|
49
|
+
)
|
|
50
|
+
documents = store.as_retriever(search_kwargs={"k": 1}).invoke(
|
|
51
|
+
"Who owns operations?"
|
|
52
|
+
)
|
|
53
|
+
print(documents[0].page_content)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The factory creates a missing table or reuses a compatible one. Stable document
|
|
57
|
+
IDs make repeated writes update the same records. To attach without writing,
|
|
58
|
+
construct `AntflyVectorStore(client=client, table="langchain_example", embedding=embeddings)`.
|
|
59
|
+
Delete this example's dedicated table with `client.drop_table("langchain_example")`
|
|
60
|
+
inside the client context when finished. Async factories, retrieval and mutations
|
|
61
|
+
are also available.
|
|
62
|
+
|
|
63
|
+
## More examples
|
|
64
|
+
|
|
65
|
+
- [Persistent PDF and image RAG](https://github.com/antflydb/langchain-antfly/tree/main/examples/multimodal):
|
|
66
|
+
extract text and images, retrieve persistent parents and original media, and
|
|
67
|
+
generate answers with an existing vision provider.
|
|
68
|
+
- [Hybrid search, reranking, graph context and caching](https://github.com/antflydb/langchain-antfly/blob/main/docs/recipes.md).
|
|
69
|
+
- [API reference and limitations](https://github.com/antflydb/langchain-antfly/blob/main/docs/api-reference.md).
|
|
70
|
+
- [Validation evidence](https://github.com/antflydb/langchain-antfly/blob/main/docs/validation-report.md).
|
|
71
|
+
|
|
72
|
+
Persistent LangGraph agent memory is available separately in
|
|
73
|
+
`langgraph-store-antfly`. This package does not include a chat-model adapter or
|
|
74
|
+
an execution checkpointer.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
[project]
|
|
5
|
+
name = "langchain-antfly"
|
|
6
|
+
version = "0.1.0rc1"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
description = "Persistent retrieval, inference, documents and graphs for LangChain with Antfly"
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
keywords = ["antfly", "langchain", "rag", "vector-search", "multimodal"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
]
|
|
20
|
+
dependencies = ["antfly-sdk>=0.2.1,<0.3", "langchain-core>=1.0,<2", "numpy>=1.26"]
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
graph = ["langchain-community>=0.4,<1"]
|
|
23
|
+
[tool.hatch.build.targets.wheel]
|
|
24
|
+
packages = ["src/langchain_antfly"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/antflydb/langchain-antfly"
|
|
28
|
+
Repository = "https://github.com/antflydb/langchain-antfly"
|
|
29
|
+
Documentation = "https://github.com/antflydb/langchain-antfly#readme"
|
|
30
|
+
Issues = "https://github.com/antflydb/langchain-antfly/issues"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Antfly integrations for LangChain. Graph dependencies are optional."""
|
|
2
|
+
|
|
3
|
+
from ._utils import WriteOutcomeError
|
|
4
|
+
from .embeddings import AntflyEmbeddings
|
|
5
|
+
from .rerankers import AntflyReranker
|
|
6
|
+
from .retrievers import AntflyRetriever
|
|
7
|
+
from .stores import AntflyByteStore, AntflyDocumentStore, AntflyJSONStore
|
|
8
|
+
from .vectorstores import AntflyVectorStore
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"AntflyEmbeddings",
|
|
12
|
+
"AntflyVectorStore",
|
|
13
|
+
"AntflyRetriever",
|
|
14
|
+
"AntflyReranker",
|
|
15
|
+
"AntflyJSONStore",
|
|
16
|
+
"AntflyDocumentStore",
|
|
17
|
+
"AntflyByteStore",
|
|
18
|
+
"WriteOutcomeError",
|
|
19
|
+
"AntflyGraphStore",
|
|
20
|
+
"create_graph_tools",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def __getattr__(name):
|
|
25
|
+
if name == "AntflyGraphStore":
|
|
26
|
+
from .graphs import AntflyGraphStore
|
|
27
|
+
|
|
28
|
+
return AntflyGraphStore
|
|
29
|
+
if name == "create_graph_tools":
|
|
30
|
+
from .tools import create_graph_tools
|
|
31
|
+
|
|
32
|
+
return create_graph_tools
|
|
33
|
+
raise AttributeError(name)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Shared transport, outcome handling, and bounded async execution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import functools
|
|
7
|
+
import json
|
|
8
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
9
|
+
from typing import Any
|
|
10
|
+
from urllib.parse import quote
|
|
11
|
+
|
|
12
|
+
_EXECUTOR = ThreadPoolExecutor(max_workers=8, thread_name_prefix="antfly-langchain")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class WriteOutcomeError(RuntimeError):
|
|
16
|
+
"""A write did not establish requested visibility. Never blindly replay it."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, status: str, keys=(), details=None, committed_keys=()):
|
|
19
|
+
self.status = status
|
|
20
|
+
self.keys = tuple(keys)
|
|
21
|
+
self.committed_keys = tuple(committed_keys)
|
|
22
|
+
self.details = details
|
|
23
|
+
self.committed = True if status.startswith("committed") else False if status == "aborted" else None
|
|
24
|
+
super().__init__(
|
|
25
|
+
f"Antfly write outcome {status} for {len(self.keys)} keys: {details}. "
|
|
26
|
+
"Inspect committed data/index status before retrying; mutations are not replayed."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def response_dict(value: Any) -> dict[str, Any]:
|
|
31
|
+
if hasattr(value, "to_dict"):
|
|
32
|
+
value = value.to_dict()
|
|
33
|
+
if not isinstance(value, dict):
|
|
34
|
+
raise ValueError("Antfly returned a non-object response")
|
|
35
|
+
return value
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def request(client, method: str, path: str, **kwargs):
|
|
39
|
+
"""Use the public SDK transport, including status codes and byte bounds."""
|
|
40
|
+
return client.request(method, path, **kwargs)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def check_write_result(result, keys=(), wait=True):
|
|
44
|
+
try:
|
|
45
|
+
body = response_dict(result)
|
|
46
|
+
except (ValueError, TypeError, AttributeError) as exc:
|
|
47
|
+
raise WriteOutcomeError("unknown", keys, "Antfly returned an unusable mutation outcome") from exc
|
|
48
|
+
status = body.get("status")
|
|
49
|
+
if not isinstance(status, str):
|
|
50
|
+
raise WriteOutcomeError("unknown", keys, body)
|
|
51
|
+
if status == "committed" or (status == "committed_pending" and not wait):
|
|
52
|
+
return body
|
|
53
|
+
raise WriteOutcomeError(status or "unknown", keys, body.get("failure", body))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _write_batch(client, table, inserts, deletes, wait, transforms=None):
|
|
57
|
+
keys = list((inserts or {}).keys()) + list(deletes or [])
|
|
58
|
+
keys += [x["key"] for x in (transforms or [])]
|
|
59
|
+
try:
|
|
60
|
+
result = client.batch(
|
|
61
|
+
table,
|
|
62
|
+
inserts=inserts,
|
|
63
|
+
deletes=deletes,
|
|
64
|
+
transforms=transforms,
|
|
65
|
+
sync_level="full_index" if wait else "write",
|
|
66
|
+
)
|
|
67
|
+
except (TimeoutError, OSError) as exc:
|
|
68
|
+
raise WriteOutcomeError("unknown", keys, str(exc)) from exc
|
|
69
|
+
except Exception as exc:
|
|
70
|
+
import httpx
|
|
71
|
+
from antfly import AntflyHTTPError, AntflyResponseError
|
|
72
|
+
|
|
73
|
+
if isinstance(exc, (httpx.TransportError, AntflyResponseError)) or (
|
|
74
|
+
isinstance(exc, AntflyHTTPError) and (exc.status_code == 408 or exc.status_code >= 500)
|
|
75
|
+
):
|
|
76
|
+
raise WriteOutcomeError("unknown", keys, str(exc)) from exc
|
|
77
|
+
raise
|
|
78
|
+
return check_write_result(result, keys, wait)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def write(client, table, inserts=None, deletes=None, wait=True, transforms=None):
|
|
82
|
+
"""Bound request size and report partial progress without mutation replay.
|
|
83
|
+
|
|
84
|
+
Transforms are one indivisible batch (memory markers and rows are atomic).
|
|
85
|
+
Ordinary insert/delete workloads split at 64 records or the SDK byte limit.
|
|
86
|
+
"""
|
|
87
|
+
if transforms is not None:
|
|
88
|
+
return _write_batch(client, table, inserts, deletes, wait, transforms)
|
|
89
|
+
rows = [("insert", key, value) for key, value in (inserts or {}).items()]
|
|
90
|
+
rows += [("delete", key, None) for key in (deletes or [])]
|
|
91
|
+
limit = getattr(client, "max_write_request_bytes", 64 << 20)
|
|
92
|
+
if not isinstance(limit, int) or limit <= 0:
|
|
93
|
+
limit = 64 << 20
|
|
94
|
+
|
|
95
|
+
def encoded(value):
|
|
96
|
+
return len(json.dumps(value, separators=(",", ":"), ensure_ascii=False, allow_nan=False).encode("utf-8"))
|
|
97
|
+
|
|
98
|
+
overhead = encoded({"inserts": {}, "deletes": [], "sync_level": "full_index" if wait else "write"})
|
|
99
|
+
sizes = [encoded({key: value}) if kind == "insert" else encoded(key) + 1 for kind, key, value in rows]
|
|
100
|
+
if any(size + overhead > limit for size in sizes):
|
|
101
|
+
raise ValueError(f"A document exceeds the SDK {limit} byte write limit; no mutations were submitted")
|
|
102
|
+
batches, batch, used = [], [], overhead
|
|
103
|
+
for row, size in zip(rows, sizes, strict=True):
|
|
104
|
+
if batch and (len(batch) >= 64 or used + size > limit):
|
|
105
|
+
batches.append(batch)
|
|
106
|
+
batch, used = [], overhead
|
|
107
|
+
batch.append(row)
|
|
108
|
+
used += size
|
|
109
|
+
if batch:
|
|
110
|
+
batches.append(batch)
|
|
111
|
+
completed_keys, outcome = [], {"status": "committed"}
|
|
112
|
+
for batch in batches:
|
|
113
|
+
keys = [key for _, key, _ in batch]
|
|
114
|
+
try:
|
|
115
|
+
outcome = _write_batch(
|
|
116
|
+
client,
|
|
117
|
+
table,
|
|
118
|
+
{key: value for kind, key, value in batch if kind == "insert"} or None,
|
|
119
|
+
[key for kind, key, _ in batch if kind == "delete"] or None,
|
|
120
|
+
wait,
|
|
121
|
+
)
|
|
122
|
+
except WriteOutcomeError as exc:
|
|
123
|
+
exc.committed_keys = tuple(completed_keys) + exc.committed_keys
|
|
124
|
+
raise
|
|
125
|
+
except Exception as exc:
|
|
126
|
+
if completed_keys:
|
|
127
|
+
raise WriteOutcomeError("partial", keys, str(exc), completed_keys) from exc
|
|
128
|
+
raise
|
|
129
|
+
completed_keys.extend(keys)
|
|
130
|
+
return outcome
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def hits(response) -> list[dict[str, Any]]:
|
|
134
|
+
"""Read one table query without turning omitted evidence into empty hits."""
|
|
135
|
+
body = response_dict(response)
|
|
136
|
+
responses = body.get("responses", [body])
|
|
137
|
+
if not isinstance(responses, list) or len(responses) != 1 or not isinstance(responses[0], dict):
|
|
138
|
+
raise RuntimeError("Antfly query requires exactly one response object for its table")
|
|
139
|
+
response = responses[0]
|
|
140
|
+
if response.get("status", 200) != 200 or response.get("error"):
|
|
141
|
+
raise RuntimeError(f"Antfly query failed: {response}")
|
|
142
|
+
group = response.get("hits")
|
|
143
|
+
found = group.get("hits") if isinstance(group, dict) else group
|
|
144
|
+
if not isinstance(found, list) or any(not isinstance(hit, dict) for hit in found):
|
|
145
|
+
raise RuntimeError("Antfly query omitted or returned malformed hits")
|
|
146
|
+
return found
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
async def run_async(fn, *args, **kwargs):
|
|
150
|
+
# Bound queued as well as running operations. One semaphore per event loop
|
|
151
|
+
# avoids retaining closed loops and permits independent asyncio.run calls.
|
|
152
|
+
loop = asyncio.get_running_loop()
|
|
153
|
+
sem = getattr(loop, "_antfly_concurrency", None)
|
|
154
|
+
if sem is None:
|
|
155
|
+
sem = asyncio.Semaphore(16)
|
|
156
|
+
loop._antfly_concurrency = sem
|
|
157
|
+
await sem.acquire()
|
|
158
|
+
try:
|
|
159
|
+
future = loop.run_in_executor(_EXECUTOR, functools.partial(fn, *args, **kwargs))
|
|
160
|
+
except BaseException:
|
|
161
|
+
sem.release()
|
|
162
|
+
raise
|
|
163
|
+
|
|
164
|
+
def completed(done):
|
|
165
|
+
sem.release()
|
|
166
|
+
if not done.cancelled():
|
|
167
|
+
done.exception() # Observe worker errors even if the awaiting task was cancelled.
|
|
168
|
+
|
|
169
|
+
future.add_done_callback(completed)
|
|
170
|
+
return await asyncio.shield(future)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def path_part(value: str) -> str:
|
|
174
|
+
return quote(value, safe="")
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def json_copy(value):
|
|
178
|
+
return json.loads(json.dumps(value, ensure_ascii=False, allow_nan=False))
|