Compare commits

..
823 Commits
Author SHA1 Message Date
Hua.T e981d2d8fc Forward backend options during streaming speech generation (#1389) (#1390) 2026-10-11 17:23:05 -04:00
PerryLink 55fadb4c56 Reject a semicolon in a SQL query instead of silently cutting the statement (#1388) 2026-10-11 17:21:01 -04:00
Rızgar Ozan fe5be99bfa Handle ServiceTask responses without a Content-Type or body (#1387) 2026-10-11 17:17:06 -04:00
David Mezzetti 243aaa191d Merge pull request #1385 from kartsan03/sqlite-load-switch
Switch SQLite ANN connections when load() is given a new path
2026-10-11 17:13:58 -04:00
leeshengis 93a767f004 Preserve workflow and task configuration dictionaries (#1377) 2026-10-11 17:12:41 -04:00
davidmezzetti 62099b9a34 Cleanup open connection in test 2026-10-11 12:03:14 -04:00
David Mezzetti c786f1b5ec Replace continue statement in HTMLToMarkdown list handler (#1357) (#1386) 2026-10-11 11:02:08 -04:00
amengnew 738df97d5f Fall back to row index when Tabular IDs are NaN (#1366) 2026-10-11 10:37:51 -04:00
Raphael Malikian 4605ee001f Fix LogOdds.calibrate to compute the mean once instead of per score (#1365) 2026-10-10 08:06:37 -04:00
Rızgar Ozan 46516fa4e6 Replace continue statement in HTMLToMarkdown list handler (#1357) 2026-10-10 14:24:22 +03:00
kartsan03 fe1fbbc933 Switch SQLite ANN connections when load() is given a new path 2026-10-10 11:11:24 +00:00
Hua.T 084a1eca4d Fix audio trimming of partial detection windows (#1374) (#1375) 2026-10-10 06:35:44 -04:00
Muneeb Ullah ba9d52310a Fix infertopics ignoring topiced neighbors when untopiced ones outnumber them (#1373) 2026-10-10 06:33:12 -04:00
Jasper ca9563daac Use only the query argument of similar() clauses in terms and explain (#1367) 2026-10-09 10:29:46 -04:00
D41910 0e7202caee Honor an empty allow list in the bash agent tool (#1362) 2026-10-08 15:55:25 -04:00
David Mezzetti c1f1686889 Merge pull request #1361 from kartsan03/rdbms-graph-addattribute
Write RDBMS graph attribute changes to the database
2026-10-08 13:06:57 -04:00
kartsan03 04f5bf1998 Write RDBMS graph attribute changes to the database 2026-10-08 12:52:02 +00:00
Gaurav Chintakunta c8e7d813af Preserve ordered-list start values in HTMLToMarkdown (#1355) (#1356) 2026-10-08 07:05:07 -04:00
Yuilona edf61d1d4a Use each query's hybrid weights when batching similar clauses (#1359) 2026-10-07 16:21:36 -04:00
Raphael Malikian 7e92f5a7d7 Fix StorageTask listing failing on tagged storage inputs (#1348) 2026-10-07 14:15:17 -04:00
Raashish Aggarwal b2ff9bd85c Sort NULL values like SQLite when merging ordered results (#1353) 2026-10-07 13:09:08 -04:00
Raashish Aggarwal 9c718f7876 Merge aggregate columns written in uppercase across shards (#1352) 2026-10-07 09:00:39 -04:00
Moinuddin Shaik c486f4706e Return no results from Reranker when a search has no matches (#1350) 2026-10-07 09:00:03 -04:00
Lukas 341184ba46 Keep word spacing and drop empty link targets in HTMLToMarkdown (#1347) 2026-10-07 08:58:51 -04:00
Lukas 647d80f95e Replace HTML line breaks with newlines in HTMLToMarkdown (#1345) 2026-10-07 07:22:03 -04:00
Yash Raj Pandey 408c25d201 Explain DuckDB query errors that abort the transaction (#1341) 2026-10-07 06:34:30 -04:00
davidmezzetti b0f29a11d1 Bump Docker version 2026-10-06 10:18:15 -04:00
davidmezzetti 49a64943b8 Bump version 2026-10-06 10:18:02 -04:00
David Mezzetti af33f2e024 Merge pull request #1333 from HuaTNA/fix-tabular-falsy-idcolumn
Respect explicitly selected falsy ID column names in Tabular
2026-10-05 11:06:24 -04:00
davidmezzetti f908b5d88d Support trust_remote_code in associated AutoModels, closes #1342 2026-10-05 10:25:41 -04:00
David Mezzetti 2e8493dfca Merge pull request #1338 from serhiizghama/fix/duckdb-bind-parameter-order
Keep DuckDB bind values in query order when a parameter repeats
2026-10-05 08:53:15 -04:00
shabeeth2 d7e3e29ac3 docs: match task input tuple in explanation (#1337) 2026-10-05 06:22:06 -04:00
Mohammad Hijjawi 4e2efa2cbc Keep node id 0 in graph path search results (#1335) 2026-10-05 06:19:12 -04:00
Gaurav Chintakunta ffcbc0b815 Skip NULL aggregate values from shards with no matching rows (#1331) 2026-10-05 06:17:05 -04:00
tuanzirwar f14c26c4c7 Fix ordinary streaming output buffering with stripthink enabled (#1311) 2026-10-05 06:15:44 -04:00
serhiizghama 346bb9d282 Test a repeated bind parameter followed by another parameter 2026-10-05 11:12:23 +07:00
serhiizghama e3e0413747 Keep DuckDB bind values in query order when a parameter repeats 2026-10-05 10:47:53 +07:00
David Mezzetti 32655393e0 Merge pull request #1323 from Lesereingrape/fix/concat-merge-falsy-values-1003
Keep 0 and False in concat merge outputs
2026-10-04 11:08:45 -04:00
davidmezzetti 9118875980 Move coverage check to only run for Linux GitHub action 2026-10-04 09:45:08 -04:00
Manobhi Sriram d9b4476187 Decode bash tool output as UTF-8 instead of locale encoding, closes #1326 (#1327) 2026-10-04 09:32:30 -04:00
Grapette.L ff5aec468a Fix DuckDB bind parameters followed by a non-word character not being converted (#1325) 2026-10-04 09:01:16 -04:00
davidmezzetti 3446a4ef13 Fail if code coverage less than 100% 2026-10-04 08:57:07 -04:00
HuaTNA 84aa1c81c7 Fix Tabular handling of explicitly selected falsy ID columns (#1332) 2026-10-03 19:14:23 -04:00
Lesereingrape 6bc76132d0 Keep 0 and False in concat merge outputs 2026-10-03 11:34:59 +08:00
Morgan Carr 893d0424be Cache document token vectors in Reranker (#1321) 2026-10-02 14:32:17 -04:00
Edson 98c965cc3b Keep all rows for native vstack merges with list inputs (#1320) 2026-10-02 14:30:31 -04:00
Yash Raj Pandey 00622f2cf1 Parse true and false as boolean literals in SQL queries (#1316) 2026-10-02 14:28:51 -04:00
Yash Raj Pandey 55d52fda92 Keep graph categories aligned with topics after a delete (#1315) 2026-10-02 14:24:59 -04:00
Ni0ri 20c9b8e0be Add Zvec Sparse ANN (#1307) 2026-10-01 09:53:38 -04:00
Mohammad Hijjawi 3f33fb2918 Format nested HTML lists without duplicating items (#1286) 2026-10-01 06:48:14 -04:00
davidmezzetti 3c7a548923 Remove build script workaround, closes #1239 2026-09-30 13:03:03 -04:00
Pablo Miguel Argudo c78fbd976c Support append and delete in the RaBitQ ivf mode (#1304) 2026-09-30 12:44:19 -04:00
David Mezzetti 2d535ff215 Merge pull request #1303 from kartsan03/fix/ann-delete-numpy-ids
Delete the requested rows when ANN ids are a NumPy array
2026-09-30 12:40:40 -04:00
kartsan03 6765330f4a Delete the requested rows when ANN ids are a NumPy array 2026-09-30 15:26:24 +00:00
davidmezzetti 1d5041b6e7 Fix test merge error 2026-09-30 11:07:02 -04:00
davidmezzetti d467878064 Refactor ANN tests, closes #1305 2026-09-30 11:04:07 -04:00
davidmezzetti 3bc07b3f09 Remove unnecessary note 2026-09-30 11:03:37 -04:00
Hua.T 8ef454d0bf Preserve keyword document ID types across save/load (#1274) (#1275) 2026-09-30 10:57:41 -04:00
Jin 47d3e65756 Fix training with pandas DataFrames, closes #1265 (#1266) 2026-09-30 10:55:44 -04:00
LimbC-C 81f908874b Open lazy SQLite connections before saving indexes (#1290) 2026-09-30 09:30:14 -04:00
David Mezzetti bed91a0b9f Merge pull request #1301 from Bdysj/openai-compliant-chat-completions
Return OpenAI-compliant index, created and finish_reason from chat completions
2026-09-30 09:05:50 -04:00
David Mezzetti 7df50abb61 Merge pull request #1282 from LimbC-C/fix/sqlite-binary-scores
Normalize SQLite binary ANN similarity scores
2026-09-30 09:03:45 -04:00
David Mezzetti 80b8ceff4a Merge pull request #1279 from LimbC-C/fix/array-negative-delete-ids
Ignore negative deletion IDs in NumPy and Torch ANN indexes
2026-09-30 08:59:03 -04:00
David Mezzetti de9e09e9ae Merge pull request #1299 from LimbC-C/fix/tabular-numeric-types
Preserve integer document IDs and numeric column types in Tabular
2026-09-30 08:19:59 -04:00
Morgan Carr 69ede9ec3e Fall back to root tokenizers for ONNX and LiteRT Hub subdirectory models (#1277) 2026-09-30 07:41:03 -04:00
Pablo Miguel Argudo f8689ed903 Store only the quantized index in the RaBitQ backend (#1297) 2026-09-30 07:05:37 -04:00
bob 0abf3763b4 Return OpenAI-compliant index, created and finish_reason from chat completions, closes #1300 2026-09-30 14:51:02 +08:00
LimbC-C 11b2cfe298 Preserve numeric column types in Tabular rows (#1298) 2026-09-30 09:45:58 +08:00
LimbC-C d0cc2bed9c Simplify regression test in existing TestDense class (#1282) 2026-09-30 09:39:23 +08:00
LimbC-C a5ea35d7a7 Simplify regression test in existing TestDense class (#1279) 2026-09-30 09:39:18 +08:00
Yash Raj Pandey 6a15ed8490 Include offset rows in similar() candidates (#1291) 2026-09-29 17:25:52 -04:00
David Mezzetti 76147369fb Merge pull request #1295 from Bdysj/pad-summary-batches
Pad batched inputs in the Summary pipeline
2026-09-29 15:27:58 -04:00
bob 2e89af0845 Pad batched inputs in the Summary pipeline, closes #1294 2026-09-30 01:19:38 +08:00
davidmezzetti d9d6a1cbb1 Update pooling mode check 2026-09-29 11:05:04 -04:00
davidmezzetti f87574de4c Support pooling_mode with models trained with recent Sentence Transformers, closes #1292 2026-09-29 10:23:16 -04:00
Mohammad Hijjawi e313248ff2 Keep uppercase tokens in alphanumeric tokenization with lowercase=False (#1287) 2026-09-29 09:03:03 -04:00
davidmezzetti 5cba72c88a Update pylintrc file and remove warning overrides for new limits 2026-09-29 07:11:03 -04:00
davidmezzetti 45d334f4ce Remove unnecessary new test file and consolidate test into existing class 2026-09-29 07:10:09 -04:00
Jin 95d4c1c881 Label QA spans without the answer with the CLS token, closes #1263 (#1264) 2026-09-29 06:36:47 -04:00
LimbC-C ef28da8735 Reject iterator inputs for multi-action tasks without buffering (#1272) 2026-09-28 10:40:36 -04:00
LimbC-C f1304d8403 Normalize SQLite binary ANN similarity scores (#1281) 2026-09-28 09:43:12 +08:00
davidmezzetti 97ee7e073a Bump job timeout given that the Windows build frequently times out 2026-09-27 05:51:01 -04:00
LimbC-C 1d3f8e9ebf Ignore negative NumPy and Torch ANN deletion IDs (#1278) 2026-09-26 09:43:32 +08:00
davidmezzetti f3ceece76a Add test for missing SQLite ANN coverage 2026-09-25 09:18:02 -04:00
Pablo Miguel Argudo 6737ee4e01 Add RaBitQ as an ANN backend (#1251) 2026-09-25 08:39:39 -04:00
davidmezzetti e30e8edbcc Add test for missing SQLite ANN coverage 2026-09-25 08:00:21 -04:00
davidmezzetti 483dbd3b3b Update test 2026-09-24 21:49:06 -04:00
davidmezzetti c09a6f24f1 Update test 2026-09-24 21:46:09 -04:00
davidmezzetti 6e7f0d260e Update test 2026-09-24 21:12:15 -04:00
davidmezzetti 793ecc8dc2 Require Python 3.11, closes #1273 2026-09-24 16:58:32 -04:00
David Mezzetti 37500887ae Merge pull request #1268 from HuaTNA/fix-rag-input-mutation
Preserve reusable RagTask inputs
2026-09-24 16:35:58 -04:00
David Mezzetti 4e2eb242b6 Support explicit LIKE escapes in wildcard term queries (#1259) 2026-09-24 16:34:16 -04:00
Jin 83c75ea28a Pack rows into chunks up to and including maxlength, closes #1269 (#1270) 2026-09-24 16:31:37 -04:00
LimbC-C f47d389735 Preserve wildcard compatibility and support explicit LIKE escapes 2026-09-24 23:54:33 +08:00
HuaTNA 4bb2141954 Preserve reusable RagTask inputs (#1267) 2026-09-23 23:48:46 -04:00
David Mezzetti 5d8c999ae0 Merge pull request #1262 from HuaTNA/fix-template-falsy-rules
Preserve falsy TemplateTask rule matches
2026-09-23 16:36:47 -04:00
HuaTNA 48a34e21c3 Preserve falsy TemplateTask rule matches (#1261) 2026-09-23 13:22:36 -04:00
davidmezzetti 262b03027e Code cleanup 2026-09-23 08:01:47 -04:00
刘冠杰 36c375b86e Honor the nfeatures setting in IVFSparse (#1250) 2026-09-23 07:53:18 -04:00
David Mezzetti b715812e68 Merge pull request #1248 from LimbC-C/fix/deleted-keyword-results
Keep deleted keyword results excluded after common-term scoring
2026-09-23 07:51:27 -04:00
hylin dcdded892d Keep community nodes that match none of the topic terms (#1243) 2026-09-23 07:40:25 -04:00
LimbC-C e7894cdb00 Escape literal SQL wildcard characters in term expansion (#1258) 2026-09-23 13:06:27 +08:00
LimbC-C 9f9b32e070 Clear deleted scores at the end of common-term merging 2026-09-23 13:00:30 +08:00
David Mezzetti 00167b9f08 Merge pull request #1256 from dingpuyu/codex/fix-retrieve-local-filenames
Preserve local filenames in RetrieveTask
2026-09-22 14:00:19 -04:00
dingpuyu 3c07766199 Preserve local filenames in RetrieveTask 2026-09-23 00:36:08 +08:00
Amir Fathi 7cb6bd09db Fix DuckDB.formatargs dropping repeated named bind parameters (#1253) 2026-09-22 12:22:45 -04:00
Caner Olcay 4b7d70e9e8 Keep SQLite ANN data when saving a modified index to a new path (#1249) 2026-09-22 06:55:29 -04:00
David Mezzetti 2ed4e46ebf Merge pull request #1245 from serhiizghama/fix/cluster-forward-weights-and-encode-parameters
fix(api): forward zero weights and url-encode parameters in Cluster search
2026-09-22 06:54:14 -04:00
LimbC-C 47d5f56768 Keep deleted keyword results excluded after common-term scoring (#1247) 2026-09-19 09:46:09 +08:00
serhiizghama d5db643540 test: cover cluster search argument forwarding 2026-09-18 09:15:19 +07:00
serhiizghama 9f7b4ddd42 fix(api): forward zero weights and url-encode parameters in Cluster search 2026-09-18 08:56:12 +07:00
Morgan Carr 19ff237c37 Set the HNSW delete counter when loading an index (#1242) 2026-09-15 14:21:46 -04:00
Morgan Carr ad77514b32 Store IVFSparse deletes as int (#1241) 2026-09-15 14:20:36 -04:00
davidmezzetti 144a957d42 Test latest version of LiteLLM #1193 2026-09-15 07:51:21 -04:00
Serhii Zghama 2e8a3d7892 fix(database): don't drop rows when sorting or grouping by a JSON field (#1238) 2026-09-14 10:19:52 -04:00
Amir Fathi 72f9ca7605 Fix Cluster combining avg() as an unweighted mean of shard averages (#1237) 2026-09-14 10:18:52 -04:00
Amir Fathi ebe13ae304 Fix quantize: false silently enabling Q8_0 quantization in the GGML backend (#1236) 2026-09-11 08:25:40 -04:00
Serhii Zghama 5d0e995f7f fix(ann): honor quantize: false in the Faiss and SQLite backends (#1234) 2026-09-11 08:22:49 -04:00
davidmezzetti 7965a7f42e Build script workaround #1239 2026-09-10 08:52:56 -04:00
Amir Fathi 2bae6e4d43 Fix Transform.stream() yielding a None text value into the encoder (#1231) 2026-09-08 09:44:53 -04:00
Morgan Carr 767272f2d5 Key the vectors model cache by configuration (#1223) 2026-09-04 16:47:49 -04:00
Morgan Carr 21460347dd Fix ANN delete on quantized Torch stores and tiny GGML indexes (#1228) 2026-09-04 09:54:42 -04:00
Morgan Carr f3945f9120 Select the top documents in LateEncoder by the document axis (#1227) 2026-09-04 09:52:40 -04:00
Paco Cartones 3a7b597d78 fix(workflow): add request timeout to ServiceTask (#1226) 2026-09-04 09:00:49 -04:00
Morgan Carr 20e2dc41e1 Save empty keyword and content indexes without errors (#1224) 2026-09-04 08:21:11 -04:00
Morgan Carr eafe574d92 Keep the archive working directory alive when saving a loaded index (#1222) 2026-09-04 08:19:36 -04:00
Morgan Carr 7e98746d78 Delete every index entry for an id in Terms (#1219) 2026-09-04 08:11:47 -04:00
Morgan Carr 6ebfbbb716 Improve late pooling configuration errors (#1217) 2026-09-03 13:52:46 -04:00
David Mezzetti 8fef6ac454 Merge pull request #1220 from serhiizghama/fix/sparse-vectors-remove-spool-file
fix(vectors): remove the sparse spool file when checkpointing is disabled
2026-09-03 13:05:09 -04:00
davidmezzetti 0eafc0580f Update vectors package to standardize fallback logic, closes #1221 2026-09-03 11:53:55 -04:00
serhiizghama 5ade7881c8 test: cover spool file cleanup for sparse vectors 2026-09-03 20:19:31 +07:00
serhiizghama 948dc42d19 fix(vectors): remove the sparse spool file when checkpointing is disabled 2026-09-03 19:58:47 +07:00
David Mezzetti 2e8af221f4 Keep count() accurate after repeated deletes in GGML and IVFSparse (#1218)
Deleting an id that is already marked deleted no longer decrements count()
again in the GGML and IVFSparse ANN backends. IVFSparse also ignores ids that
were never indexed, matching the dense backends.
2026-09-02 18:18:11 -04:00
Morgan Carr 396b3b8065 Resolve label filters by label id (#1216) 2026-09-02 17:15:45 -04:00
Morgan Carr 80420ee10a Ignore padding rows in LateEncoder scores (#1215) 2026-09-02 17:14:39 -04:00
David Mezzetti 1d45e88569 Merge pull request #1214 from morgan-coded/fix/milvus-load-collection
Load the Milvus collection when opening a saved index
2026-09-02 15:25:19 -04:00
Joe Bergin 007d61077a Add ONNX vectors backend (#1212) 2026-09-02 12:19:57 -04:00
David Mezzetti 84fcd81039 fix(api): parse the graph query parameter as a bool (#1213) 2026-09-02 11:18:16 -04:00
morgan-coded cfe2227f30 Load the Milvus collection when opening a saved index
With milvus-lite 3.2.1, a reopened collection that has an index starts in the
released state, so search failed after save and after load while count worked.
2026-09-02 03:20:29 -05:00
morgan-coded 82b5320da3 Keep count() accurate after repeated deletes in GGML and IVFSparse
Deleting an id that is already marked deleted no longer decrements count()
again in the GGML and IVFSparse ANN backends. IVFSparse also ignores ids that
were never indexed, matching the dense backends.
2026-09-02 02:53:52 -05:00
serhiizghama 18b93be702 test: cover graph parameter parsing in the search API 2026-09-02 11:06:18 +07:00
serhiizghama 027c07deb9 fix(api): parse the graph query parameter as a bool 2026-09-02 10:53:23 +07:00
Paco Cartones 876cd07cf7 Fix bash tool hanging on commands that read stdin (#1210) 2026-09-01 20:04:29 -04:00
davidmezzetti 546e7777f1 Bump version 2026-08-27 12:48:36 -04:00
Yash Raj Pandey 27542ca64b Index zero and False values in the tabular pipeline (#1207) 2026-08-27 07:39:36 -04:00
David Mezzetti f0ee7d2b2d Merge pull request #1206 from morgan-coded/fix/nprobe-clamp
Clamp default Faiss nprobe to nlist
2026-08-26 08:23:31 -04:00
morgan-coded bba7fd589e Clamp default nprobe to nlist 2026-08-25 17:18:46 -05:00
David Mezzetti 6349ca2eac Merge pull request #1205 from Evhye38496/fix-safetensors-import
Fix safetensors numpy/torch submodule imports
2026-08-25 07:58:29 -04:00
Evhye38496 ba1693480e Fix safetensors numpy/torch submodule imports #1204 2026-08-25 12:57:51 +08:00
Sainikhil Juluri e90c67ef06 fix(scoring): keep count() accurate when an id is deleted more than once (#1202) 2026-08-24 21:55:11 -04:00
Amir Fathi 57991cb164 Fix WordVectors.index() silently dropping the checkpoint argument (#1198) 2026-08-24 20:38:28 -04:00
David Mezzetti c2b264d297 Merge pull request #1201 from serhiizghama/fix/numpy-hamming-search-skip-deleted-rows
fix(ann): exclude deleted rows from quantized numpy search results
2026-08-24 15:57:28 -04:00
serhiizghama 406e417be0 test(ann): cover deleted-row exclusion for quantized numpy backend 2026-08-24 17:18:26 +07:00
serhiizghama 954b17af4d fix(ann): exclude deleted rows from quantized numpy search results 2026-08-24 17:05:58 +07:00
davidmezzetti 2a139449dc Re-add LiteLLM workaround #1193 2026-08-23 19:08:33 -04:00
davidmezzetti a10667a1c2 Test new version of LiteLLM #1193 2026-08-22 22:10:01 -04:00
davidmezzetti 34e6efcdd6 Update docs 2026-08-22 22:09:34 -04:00
David Mezzetti 9b7a96b4d1 Resolve LEMUR and MUVERA settings (#1196) 2026-08-22 21:49:14 -04:00
morgan-coded b94f770301 Resolve LEMUR and MUVERA settings 2026-08-22 16:19:06 -05:00
Arnaud Thery adbcccda46 Merge pull request #1195 from St4r4x/fix/crossencoder-multiclass-labels
fix: rank CrossEncoder by a fixed label, not top-1 position
2026-08-22 14:15:21 -04:00
David Mezzetti 20f818f72c Merge pull request #1194 from morgan-coded/fix/1190-lemur-collection-centering
Fix LEMUR collection centering
2026-08-19 06:37:51 -04:00
morgan-coded ee0416e87b Add centermean validation test 2026-08-18 20:22:07 -05:00
morgan-coded 00ec81a10e Fix LEMUR collection centering 2026-08-18 10:54:10 -05:00
davidmezzetti 059ecec2ee Build script workaround #1193 2026-08-18 09:58:35 -04:00
davidmezzetti 21c2c38b98 Build script workaround #1193 2026-08-18 09:56:00 -04:00
davidmezzetti 47c05994bf Cleanup of Pooling PRs 2026-08-18 09:53:29 -04:00
Kole Harvey 8f3735101b Resolve pooling method from a config missing pooling_mode_mean_tokens 2026-08-18 09:14:20 -04:00
Aryan Pardeshi 438ade31b6 Add max pooling 2026-08-18 09:12:32 -04:00
davidmezzetti 3ea197468d Code cleanup 2026-08-12 09:35:13 -04:00
LHMQ878 99ebbdfea2 fix: create default agent tools on first use (#1175) 2026-08-12 07:30:37 -04:00
David Mezzetti 5570dbc7b6 Merge pull request #1183 from FU-max-boop/fix/openai-latest-message
Fix OpenAI chat message selection
2026-08-12 07:29:43 -04:00
FU-max-boop 01b456900a Fix OpenAI chat message selection 2026-08-11 13:26:29 +08:00
davidmezzetti a0857e980a Update output validation #1181 2026-08-10 22:02:42 -04:00
davidmezzetti 84be3476d8 Add safeopen validation to retrieve task output, closes #1181 2026-08-10 19:29:05 -04:00
davidmezzetti f35d932979 Refactor late encoding logic to cleanup logic paths, closes #1180 2026-08-10 18:47:58 -04:00
Tai An a1c9b94d00 fix(muvera): consume true token rows instead of batch-padded ones (#1177) 2026-08-10 13:24:21 -04:00
Aryan Pardeshi 11ebacdb23 Convert MUVERA algorithm from NumPy to Torch (#1178) 2026-08-10 13:20:58 -04:00
davidmezzetti 5986fa6082 Test Docling build #1176 2026-08-10 10:57:48 -04:00
davidmezzetti 893a333887 Test Docling build fix #1176 2026-08-10 10:15:16 -04:00
David Mezzetti e54255f4e4 Merge pull request #1179 from latent-9/fix-spelling-typos
Fix spelling typos in documentation and docstrings
2026-08-10 09:08:58 -04:00
latent-9 f89835bc77 Fix spelling typos in documentation and docstrings 2026-08-10 04:40:37 +12:00
davidmezzetti ea531b3420 Build script workaround #1176 2026-08-04 12:24:05 -04:00
davidmezzetti 756917f14b Build script workaround #1176 2026-08-04 12:20:17 -04:00
davidmezzetti b1f4845284 Build script workaround #1176 2026-08-04 12:13:14 -04:00
David Mezzetti d2b1d3634f Merge pull request #1172 from morgan-coded/feat/lemur-trainer
Consolidate LEMUR training in the trainer pipeline
2026-08-04 10:12:05 -04:00
morgan-coded 193facd144 test: cover the tqdm library stub 2026-08-03 20:50:04 -05:00
morgan-coded 436662e32b feat: promote tqdm to a default library dependency 2026-08-03 14:32:12 -05:00
morgan-coded 54644a0526 chore: add lint pragma and docstring for relocated trainer tests 2026-08-02 18:11:54 -05:00
morgan-coded 817a2b142a fix: keep minimal installs importable 2026-08-02 17:04:51 -05:00
morgan-coded 987cff001f feat: consolidate LEMUR training in trainer
Move fitting, data preparation, model setup, epoch selection and progress feedback into LemurTrainer while keeping artifact loading and encoding in the pooler.
2026-08-02 16:55:32 -05:00
David Mezzetti 8383e6ce8d Merge pull request #1171 from morgan-coded/chore/lemur-style
Align LEMUR names with txtai style
2026-08-02 16:49:32 -04:00
morgan-coded 0be1231d8d chore: align LEMUR names with txtai style 2026-08-02 14:21:38 -05:00
David Mezzetti 79e277fb7d Merge pull request #1168 from morgan-coded/feat/center
Add configurable mean centering to late pooling
2026-08-02 13:36:13 -04:00
morgan-coded f4472312ba test: use portable tolerances for cross-batch comparisons 2026-08-02 06:47:56 -05:00
morgan-coded 90f7cc2078 test: isolate uncentered LEMUR coverage 2026-08-01 22:40:57 -05:00
morgan-coded ce11b08ab1 fix: address centering review feedback 2026-08-01 22:13:38 -05:00
morgan-coded 75b4ce5c7f feat: add configurable late pooling centering 2026-08-01 18:37:42 -05:00
David Mezzetti 2ef401bb78 Merge pull request #1164 from morgan-coded/feat/lemur
Add LEMUR fixed dimensional encoding
2026-08-01 17:35:07 -04:00
davidmezzetti 8c43c70687 Bump version 2026-07-30 17:43:11 -04:00
David Mezzetti 48e22b593c Merge pull request #1163 from AmirF194/fix/scoring-delete-unindexed-id
Fix Scoring.delete() crashing on ids that were never indexed
2026-07-30 14:48:11 -04:00
davidmezzetti 3beea7f4bf Add safeopen option for retrieve task, closes #1166 2026-07-30 14:36:52 -04:00
morgan-coded 626cc8fbe0 Add LEMUR validation coverage 2026-07-30 12:03:07 -05:00
davidmezzetti 21b9049c86 Allow disabling API routes, closes #1165 2026-07-30 12:49:38 -04:00
davidmezzetti abf504f70e Update configuration section for workflow tasks 2026-07-30 12:44:34 -04:00
davidmezzetti d9e9a9e684 Pin mcp < 2.0 until upstream issues resolved #1161 2026-07-30 12:43:47 -04:00
Amir Fathi bd199158b6 Fix Scoring.delete() crashing on ids that were never indexed 2026-07-30 12:35:35 +00:00
morgan-coded 390cc08b11 Document LEMUR training and configuration 2026-07-30 07:02:16 -05:00
morgan-coded feac4c8306 Test LEMUR pooling and training 2026-07-30 07:02:16 -05:00
morgan-coded d7f974b3d7 Add LEMUR training pipeline 2026-07-30 07:02:16 -05:00
morgan-coded d8fa848f73 Integrate LEMUR late pooling 2026-07-30 07:02:16 -05:00
morgan-coded bbd23bb12c Add LEMUR fixed dimensional encoding 2026-07-30 07:02:16 -05:00
David Mezzetti 8362110c64 Merge pull request #1162 from morgan-coded/fix/milvus-lite-version-floor
Set minimum milvus-lite version
2026-07-29 07:51:07 -04:00
morgan-coded 83e1835b6d Set minimum milvus-lite version 2026-07-28 20:33:31 -05:00
davidmezzetti cf2368269f Build script workaround #1161 2026-07-28 11:14:49 -04:00
davidmezzetti a910ddbbea Add Milvus tests on Windows #1156 2026-07-28 10:37:38 -04:00
davidmezzetti 7b49504dca Update test 2026-07-23 11:54:09 -04:00
davidmezzetti 86af7ec344 Test updates 2026-07-23 10:10:28 -04:00
Amir Fathi 50ca7b2fde Fix HNSW search RuntimeError when limit exceeds indexed element count (#1159) 2026-07-23 08:42:33 -04:00
David Mezzetti 7c8d001492 Merge pull request #1151 from link89/fix-openapi-auth-ui
fix Swagger UI auth issue
2026-07-23 08:30:09 -04:00
weihong.xu dea0a65fd1 implement auth with HTTPBearer for correct openapi spec 2026-07-23 09:56:26 +08:00
davidmezzetti a1224c06f1 Doc and test update 2026-07-22 09:43:36 -04:00
davidmezzetti 162b65d3d9 Remove file 2026-07-22 07:38:17 -04:00
davidmezzetti 363f8ca7cf Ensure explain / batchexplain don't return numpy values, closes #1157 2026-07-22 06:53:07 -04:00
davidmezzetti 1d084941f4 Code cleanup 2026-07-22 06:37:42 -04:00
Andrew Chen 597ba8133d Fix msgpack Accept header crashing streaming API endpoints (#1144) 2026-07-22 06:14:07 -04:00
Andrew Chen 6bbb25872a Fix Terms KeyError on a query with no similar() clause (#1142) 2026-07-22 06:13:33 -04:00
davidmezzetti f22bf5bbb5 Update test 2026-07-21 14:29:12 -04:00
davidmezzetti 83871c6fe3 Add documentation for Milvus ANN 2026-07-21 13:24:23 -04:00
davidmezzetti 2c6ec162d0 Skip Milvus tests on Windows #1156 2026-07-21 13:10:56 -04:00
davidmezzetti d59c88424d Code cleanup 2026-07-21 12:59:57 -04:00
David Mezzetti 95c7b8df1e Merge pull request #1149 from morgan-coded/milvus-lite-backend
Add milvus-lite embedded dense ANN backend
2026-07-21 12:41:05 -04:00
Loi Nguyen 2389b5946c Fix Segmentation dropping paragraph/section splits on CRLF line endings (#1152) 2026-07-21 12:29:12 -04:00
Andrew Chen b246b642c7 Fix LIMIT bind-parameter crashing content SQL search (#1148) 2026-07-21 12:26:15 -04:00
Andrew Chen 46467a3453 Raise SQLError on empty select expressions and a dangling AS (#1147) 2026-07-21 12:24:12 -04:00
davidmezzetti fcfd340ff1 Cleanup tests 2026-07-21 12:18:35 -04:00
Andrew Chen 77965f44dd Fix Cluster.shard TypeError on tuple documents and empty-string ids (#1146) 2026-07-21 11:57:57 -04:00
Andrew Chen 7435297bac Fix console printing a traceback for a query with no results (#1145) 2026-07-21 11:51:11 -04:00
Andrew Chen 3bb34eae2e Fix Terms.search AttributeError on an empty terms index (#1143) 2026-07-21 11:40:43 -04:00
Andrew Chen 79a28641b2 Fix TemplateTask.match KeyError when a rule key is missing from element (#1141) 2026-07-21 11:25:58 -04:00
Andrew Chen 7c77c134e2 Fix HTMLToMarkdown crash on a meta description tag with no content attribute (#1140) 2026-07-21 11:23:29 -04:00
Andrew Chen d6f696d795 Fix Aggregate IndexError on a SQL query that matched nothing across shards (#1139) 2026-07-21 11:19:28 -04:00
davidmezzetti d8ae6776f8 Only resolve transform functions when env variable set, closes #1155 2026-07-21 11:07:58 -04:00
davidmezzetti e18e3d1245 Reduce verbose comment 2026-07-21 10:40:32 -04:00
Andrew Chen ee0d1a0214 fix: Task.filteredrun crashes/corrupts output for single-action tasks with merge disabled (#1138) 2026-07-21 10:16:26 -04:00
davidmezzetti 5ddedf07cd Fix test order 2026-07-21 10:13:44 -04:00
David Mezzetti 590c71f593 Merge pull request #1154 from winklemad/fix/ivfsparse-sort-order
Fix IVFSparse returning unsorted sparse ANN search results
2026-07-21 10:11:17 -04:00
winklemad c33188a0f8 Fix IVFSparse returning unsorted sparse ANN search results
IVFSparse.topn selects the top n with np.argpartition but never sorts them, so
search results came back in arbitrary order instead of ranked by score descending
like every other backend (numpy argsort, hnsw/faiss, sqlite ORDER BY, pgvector).
Sort each row by score after the partition. The LateEncoder pipeline used the same
argpartition-without-sort pattern in its ranking path and is fixed the same way.
2026-07-21 18:46:36 +05:30
davidmezzetti 638a2e12b1 Validate resolver target classes, closes #1153 2026-07-21 09:13:43 -04:00
morgan-coded 03da5c96fb Rename milvuslite backend to milvus per maintainer request 2026-07-17 08:08:57 -05:00
morgan-coded 99086302ce Add milvus-lite as a dense ANN backend 2026-07-16 11:15:18 -05:00
davidmezzetti 2f11f93743 Code cleanup 2026-07-14 15:27:55 -04:00
davidmezzetti 783d9cf680 Cleanup docs 2026-07-14 15:15:21 -04:00
David Mezzetti 281babeff7 Merge pull request #1137 from chuenchen309/fix/graph-filter-unknown-node-id
Fix Graph.filter() crash on ids that don't exist in the graph
2026-07-14 14:19:06 -04:00
David Mezzetti a71732198a Merge branch 'master' into fix/graph-filter-unknown-node-id 2026-07-14 14:18:14 -04:00
Morgan Carr 14cbe51e04 Add zvec as a dense ANN backend (#1130) 2026-07-14 13:41:35 -04:00
davidmezzetti 5d15f7fa66 Revert #1136 as it's confirmed to not be necessary 2026-07-14 13:40:09 -04:00
davidmezzetti ac2dc6a30b Code cleanup 2026-07-14 13:36:50 -04:00
chuenchen309andClaude Opus 4.8 7791174c1b Fix Graph.filter() crash on ids that don't exist in the graph
Graph.filter() unpacked self.node(node) with ** into addnode() for every
input id, but self.node() returns None for an id not present in the
graph. **None raises TypeError instead of the filter simply skipping an
id it doesn't recognize - the docstring says nodes are "nodes to select",
with no stated precondition that every id must already exist.

Skip ids where self.node() returns None instead of crashing.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-15 00:09:32 +08:00
David Mezzetti b21ba7065e Merge pull request #1136 from chuenchen309/fix/graph-insert-none-text-index-desync
Fix Graph.insert() node id desync when a document's text/object field is None
2026-07-14 11:11:06 -04:00
chuenchen309andClaude Opus 4.8 10a6b23304 Fix Graph.insert() node id desync when a document's text/object field is None
Graph.insert() decided whether a document consumed an indexid slot based
on whether the resolved text/object value was not None. But the actual
vector index offset, computed by Transform.stream() (embeddings/index/
transform.py), increments based on key presence (`self.text in
document[1]`), regardless of the value. A document like {"text": None}
consumes a real vector index slot but was skipped by Graph.insert()
without incrementing its own index counter, so every subsequent document
in the batch got assigned to the wrong graph node id - a silent,
permanent misattribution of node ids to the wrong document data.

Track slot consumption with the same key-presence criterion Transform.
stream() uses (hasfield), separately from whether a node actually gets
created for that slot (still gated on the resolved value being non-None,
so no node is created for a genuinely empty document - but the index
still advances, leaving a gap instead of shifting every later id).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-14 22:55:12 +08:00
David Mezzetti 576f0ddcd7 Merge pull request #1135 from chuenchen309/fix/filetask-urltask-non-string-crash
Fix FileTask/UrlTask crash on non-string elements
2026-07-14 10:36:26 -04:00
chuenchen309andClaude Opus 4.8 9b8a606a16 Fix FileTask/UrlTask crash on non-string elements
Task.accept() is deliberately written to tolerate arbitrary element types
(including None) so heterogeneous batches can flow through a multi-task
workflow, letting a task pass through elements it doesn't recognize rather
than crashing. UrlTask.accept and FileTask.accept override this but called
element.lower()/re.sub(..., element) unconditionally, assuming element was
already a string:

- UrlTask.accept: super().accept(element) short-circuits True whenever no
  select filter is configured, then element.lower() raises AttributeError
  on any non-string element (including None).
- FileTask.accept: re.sub(FileTask.FILE, "", element) ran before the
  isinstance(element, str) check further down, so that check was dead code
  for the exact case it looked like it guarded against, and raised
  TypeError on any non-string element.

Both now check isinstance(element, str) before doing string operations, so
non-string/None elements pass through unchanged instead of crashing.
ImageTask inherits FileTask.accept and needed no change - it's protected
by the same fix via short-circuit evaluation.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-14 21:54:43 +08:00
davidmezzetti 01344b021c Test Python with build script #1134 2026-07-14 09:33:15 -04:00
davidmezzetti dd00608b9a Test Python with build script #1134 2026-07-14 09:28:05 -04:00
davidmezzetti 702e0b880f Test Python with build script #1134 2026-07-14 09:25:48 -04:00
davidmezzetti 14ac0e4cc5 Test Python 3.11 with build script #1134 2026-07-14 09:08:13 -04:00
davidmezzetti 1f28e5401d Test Python 3.11 with build script #1134 2026-07-14 08:48:00 -04:00
davidmezzetti a84f0a388c Fix test 2026-07-13 19:47:15 -04:00
davidmezzetti 510f9c18ed Update build script 2026-07-13 17:55:21 -04:00
davidmezzetti ae67f63359 Update build script 2026-07-13 17:39:07 -04:00
davidmezzetti 0e16a22051 Update build script 2026-07-13 17:10:17 -04:00
davidmezzetti bfd0aa7ff4 Update build script 2026-07-13 17:06:29 -04:00
davidmezzetti ba2ea2db4e Update build script 2026-07-13 16:57:19 -04:00
davidmezzetti 1daac761aa Update build script 2026-07-13 16:55:07 -04:00
davidmezzetti e9e65393a0 Update build script 2026-07-13 16:52:26 -04:00
davidmezzetti 24ca4e36ca Update build script 2026-07-13 16:32:59 -04:00
davidmezzetti 8208780b6a Update build script 2026-07-13 16:30:29 -04:00
davidmezzetti c3735dd5d4 Add tokenbatch size to HFTrainer pipeline, closes #1133 2026-07-13 16:15:02 -04:00
davidmezzetti 6544d123f6 Update test to work with latest version of pgvector 2026-07-13 16:08:53 -04:00
davidmezzetti aa0a8cfc32 Cleanup code from #1125 2026-07-02 10:37:57 -04:00
David Mezzetti fc6f93828b Merge pull request #1125 from Sanjays2402/fix/unterminated-sql-clause
Raise SQLError on unterminated bracket, function and similar clauses
2026-07-02 09:41:17 -04:00
Sanjay Santhanam 796c5bb0a8 Raise SQLError on unterminated bracket, function and similar clauses
The token consumer loops in Expression.bracket(), Expression.function() and
Expression.similar() read the next token with next(iterator, (None, None)) but
never checked for the end-of-stream sentinel. When a clause was left
unterminated (e.g. "select [a from txtai", "select func(a from txtai" or
"select * from txtai where similar('abc'"), the iterator was exhausted and the
code indexed tokens[None], raising a cryptic

    TypeError: list indices must be integers or slices, not NoneType

instead of the SQLError that the database layer documents and callers catch for
invalid SQL. The parse step runs before the query is handed to the database, so
this TypeError escaped the SQLError wrapping in Database.execute().

Add Expression.advance(), a small helper that wraps next() and raises SQLError
when the token stream is exhausted mid-clause, and route the three delimited
consumer loops through it. Auto-closing the clause instead was rejected because
it would silently reinterpret malformed input (e.g. "select [a" would become the
valid column "a"), masking the user error. This mirrors the existing None-guard
convention already used in Expression.compound().

Behavior on valid queries is unchanged (advance() only diverges from the old
code path when the iterator is empty). Adds testUnterminated covering
unterminated bracket, function and similar clauses.
2026-07-01 23:11:21 -07:00
davidmezzetti 7613acd6e5 Bump version 2026-07-01 15:24:55 -04:00
davidmezzetti 9db11953c5 Bump Torch version 2026-07-01 15:24:49 -04:00
davidmezzetti 2ecf4412fc Update build script 2026-07-01 10:32:49 -04:00
davidmezzetti 13b1a0f986 Update commonprefix to commonpath, closes #1120 2026-06-22 12:58:57 -04:00
davidmezzetti 89d5207b6e Limit tabular pipeline to local CSV files, closes #1119 2026-06-22 12:55:31 -04:00
davidmezzetti 21e6ab8e6a Add missing dependency #1118 2026-06-19 11:22:36 -04:00
davidmezzetti ae898e6905 Add text extraction with LiteParse, closes #1118 2026-06-19 10:51:58 -04:00
davidmezzetti 7aee5f91af Support multiple Dense layers for Late Interaction Pooling, closes #1117 2026-06-18 13:28:01 -04:00
davidmezzetti 7844e2c597 Fix how custom encoding is added to routers, closes #1115 2026-06-16 10:40:31 -04:00
davidmezzetti f9bfc2cb0d Update test 2026-06-16 10:39:37 -04:00
David Mezzetti 535edaf3ad Merge pull request #1114 from JSap0914/fix/ngram-tokenizer-lowercase
fix(tokenizer): respect lowercase=False in ngramtokenize
2026-06-16 07:20:07 -04:00
JSap0914 f507c442fd fix(tokenizer): respect lowercase=False in ngramtokenize
ngramtokenize called text.lower() unconditionally, which silently
overrode the lowercase=False setting. __call__ already lowercases text
before delegating to ngramtokenize when self.lowercase is True, so the
extra .lower() inside ngramtokenize is both redundant for the default
case and incorrect when lowercase=False.

Remove the redundant .lower() call and add a regression test.
2026-06-16 18:51:28 +09:00
davidmezzetti 73e2f6ee51 Remove find from the default list of bash tools, closes #1113 2026-06-11 12:09:45 -04:00
davidmezzetti bc8847edb0 Set minimum transformers version 2026-06-11 11:30:50 -04:00
davidmezzetti d69b72492d Test Transformers required version 2026-06-11 09:59:24 -04:00
davidmezzetti e0ae1450b4 Use gliner fork to relax transformers version caps, closes #1112 2026-06-11 09:08:05 -04:00
davidmezzetti 24c20cc0ff Revert noisy logging workaround, closes #1106 2026-06-11 09:06:59 -04:00
davidmezzetti 5f233d4a74 Update test 2026-06-09 17:16:41 -04:00
davidmezzetti 11b32da720 Add reindex parameter for API, closes #1111 2026-06-09 15:32:04 -04:00
davidmezzetti 039568541b Add note on ALLOW_PICKLE 2026-06-09 15:31:12 -04:00
davidmezzetti df53803cf7 Add turbovec an ANN backend, closes #1109 2026-06-08 12:18:28 -04:00
davidmezzetti 3c4d32f8f7 Migrate from ggml-py to ggml-python #1105 2026-06-08 07:02:18 -04:00
davidmezzetti 68e1c5719e Bump version 2026-06-04 10:57:45 -04:00
davidmezzetti c3211fbce9 Bump Torch version 2026-06-04 10:57:39 -04:00
davidmezzetti 099b89114e Revert ggml-python migration for now until build issues are resolved #1105 2026-06-02 10:49:06 -04:00
davidmezzetti 0428a71243 Test ggml-python build 2026-06-02 10:34:58 -04:00
davidmezzetti 4ce690d225 Migrate from ggml-py to ggml-python, closes #1105 2026-06-02 10:06:50 -04:00
davidmezzetti 9bb4917c0e Update docs 2026-06-01 10:15:51 -04:00
davidmezzetti a3f95a6a26 Add a Progressive Distillation Example Notebook, closes #1104 2026-05-30 09:19:41 -04:00
davidmezzetti e8000315c0 Add a Knowledge Distillation Trainer, closes #1103 2026-05-30 09:19:14 -04:00
davidmezzetti f9ddb23c10 Reduce noisy logging messages with Transformers v5, closes #1102 2026-05-30 09:12:06 -04:00
davidmezzetti 1d058cf487 Add timeout, readlimit and IPv6 support #1100 2026-05-21 22:16:17 -04:00
davidmezzetti a5d097197e Update docs 2026-05-21 18:48:19 -04:00
davidmezzetti 32e098af84 Add URLRetrieve pipeline, closes #1100 2026-05-21 18:12:34 -04:00
davidmezzetti 8844ec96b4 Update test 2026-05-19 15:13:15 -04:00
davidmezzetti 3e8e495bd2 Add missing deps 2026-05-19 14:36:30 -04:00
davidmezzetti 9d5f82e824 Add support for LiteRT vectors, closes #1097 2026-05-19 14:30:04 -04:00
davidmezzetti 57de5b3a94 Update Dockerfile 2026-05-12 15:17:45 -04:00
davidmezzetti e240d0bb02 Bump version 2026-05-12 15:17:32 -04:00
davidmezzetti 08e3568d78 Update test 2026-05-10 05:41:38 -04:00
davidmezzetti 7ff55f32f7 LiteRT updates 2026-05-09 21:01:05 -04:00
davidmezzetti 0ca702cea2 Update tests 2026-05-08 22:52:47 -04:00
davidmezzetti bb8e9f8a03 Update test 2026-05-08 22:05:45 -04:00
davidmezzetti f2ab0087d5 Update build script 2026-05-08 21:38:16 -04:00
davidmezzetti 47620b194a Update build script 2026-05-08 21:13:55 -04:00
davidmezzetti 798ff2e0ed Add LiteRT-LM LLM, closes #1095 2026-05-08 16:26:15 -04:00
davidmezzetti 345aea0544 Zero dependency minimal install, closes #1094 2026-05-08 08:16:22 -04:00
davidmezzetti 65b72bfdfa Reduce dependencies to just numpy for minimal install, closes #1093 2026-05-07 16:27:05 -04:00
davidmezzetti b14229c1da Make transformers package optional for minimal install, closes #1091 2026-05-05 15:27:44 -04:00
davidmezzetti a0e2c9e4ab Add minimal Docker build script, closes #1092 2026-05-05 15:27:09 -04:00
davidmezzetti d0ddedc048 Add txtai_minimal package, closes #1090 2026-05-05 09:46:27 -04:00
davidmezzetti 6d15bd404a Update build script 2026-05-04 09:46:32 -04:00
davidmezzetti 20fff84a7e Support minimal install for edge devices, closes #1089 2026-05-04 09:26:52 -04:00
davidmezzetti 8643baec3e Update test 2026-05-01 11:43:39 -04:00
davidmezzetti 40c92c15d6 Code cleanup 2026-05-01 10:49:02 -04:00
davidmezzetti 8745aca849 Update test 2026-05-01 10:05:54 -04:00
davidmezzetti 109a4d3c66 Various training pipeline fixes for v5, closes #1088 2026-05-01 09:23:21 -04:00
davidmezzetti 676b997f57 Add custom Questions pipeline implementation, closes #1087 2026-05-01 09:22:07 -04:00
davidmezzetti 2f8860afde Add custom Sequences pipeline implementation, closes #1086 2026-05-01 09:21:17 -04:00
davidmezzetti 688734136c Add custom Summary pipeline implementation, closes #1085 2026-05-01 09:16:18 -04:00
davidmezzetti 1109094c78 Add custom Captions implementation, closes #1084 2026-05-01 09:15:18 -04:00
davidmezzetti cfbf235f54 Bump version 2026-04-29 13:38:32 -04:00
davidmezzetti c10a042cc3 Update build script 2026-04-29 10:41:34 -04:00
davidmezzetti f0715869a4 Test latest version of ggml-py library 2026-04-29 10:09:20 -04:00
davidmezzetti fbce87b9ee Limit template scope with Agents, closes #1080 2026-04-29 07:30:25 -04:00
davidmezzetti 0c6cb615d2 Add link to txtai paper 2026-04-21 08:52:18 -04:00
davidmezzetti 8e569462f2 Performance Improvement: Use JOIN when JSON fields being used, closes #1078 2026-04-20 10:57:57 -04:00
davidmezzetti 12c8b52b5e Update recommended models and links 2026-04-14 10:12:05 -04:00
davidmezzetti a67870aefd Update test 2026-04-08 11:20:37 -04:00
davidmezzetti 40da21b2c3 Update documentation 2026-04-08 11:02:40 -04:00
davidmezzetti 7b055c5b26 Update to handle /tmp being a symlink on macOS 2026-04-08 10:53:35 -04:00
davidmezzetti 6971dc422b Update test 2026-04-08 10:35:09 -04:00
davidmezzetti 511f479251 Add safeopen parameter for Textractor, closes #1077 2026-04-08 10:21:02 -04:00
davidmezzetti c2e2f5d86e Add support for streaming Labels pipeline, closes #1075 2026-04-07 13:16:29 -04:00
davidmezzetti efb0006793 MCP server updates, closes #899, closes #1073 2026-04-07 13:16:05 -04:00
davidmezzetti 04153bd737 Add support for last token pooling, closes #1072 2026-04-05 14:43:41 -04:00
davidmezzetti f2e02dff4a Update embeddings documentation to mention loading ONNX vector models, closes #1071 2026-04-05 10:00:51 -04:00
davidmezzetti b0b181d7e8 Remove build script workaround, closes #1067 2026-03-27 09:45:34 -04:00
davidmezzetti fe916d0049 Re-add build script workaround #1067 2026-03-27 09:25:39 -04:00
davidmezzetti a44dbd1809 Test build dependency fix #1067 2026-03-27 08:08:06 -04:00
davidmezzetti ba6d67498b Add build script workaround #1067 2026-03-27 07:37:37 -04:00
davidmezzetti 1e731c3eb7 Remove build script workaround, closes #1066 2026-03-26 13:51:08 -04:00
davidmezzetti 354b881318 Add build script workaround #1066 2026-03-24 21:29:53 -04:00
davidmezzetti 8fcfa6363a Bump torch version 2026-03-24 08:44:26 -04:00
davidmezzetti d582bf335b Bump version 2026-03-20 13:44:27 -04:00
davidmezzetti 7e3c0e16a4 Add video link 2026-03-17 13:32:32 -04:00
davidmezzetti d12a6681ea Add agent tools example notebook, closes #1062 2026-03-16 14:51:49 -04:00
davidmezzetti 80b90cdbd6 Update comment 2026-03-14 13:16:50 -04:00
davidmezzetti 6343779678 Apply sigmoid to fused BB25 scores, closes #1053 2026-03-14 13:14:29 -04:00
davidmezzetti 2d50a4c202 Add coding agent toolkit, closes #1054 2026-03-14 07:33:17 -04:00
davidmezzetti d2b3758005 Add write tool, closes #1061 2026-03-14 07:32:17 -04:00
davidmezzetti 4c03a8106f Add todowrite tool, closes #1060 2026-03-14 07:31:12 -04:00
davidmezzetti 8f583b2446 Add read tool, closes #1059 2026-03-14 07:30:37 -04:00
davidmezzetti e9c34adde3 Add grep tool, closes #1058 2026-03-14 07:30:02 -04:00
davidmezzetti 6ee6656d40 Add glob tool, closes #1057 2026-03-14 07:29:29 -04:00
davidmezzetti f388ecb4a1 Add edit tool, closes #1056 2026-03-14 07:28:57 -04:00
davidmezzetti 1a0b11654b Add bash tool, closes #1055 2026-03-14 07:28:24 -04:00
JiangNan 79908eee5a Fix translation chunk concatenation when showmodels is enabled (#1052)
* Fix translation chunk concatenation when showmodels is enabled

When translating long text that gets split into multiple chunks by the
tokenizer, the translate() method combines results from the same source
text segment. With showmodels=True, each result is a tuple (path, text).
Using += to combine tuples produces (path, text1, path, text2) instead
of the expected (path, text1+text2). This causes a ValueError when the
caller unpacks with "model, op = outputs[y]" since there are too many
values.

Fix by explicitly concatenating only the text portion of the tuple when
showmodels is enabled.

Signed-off-by: JiangNan <[email protected]>

* Add unit test for showmodels with chunked translation

Adds testLongTranslationWithShowmodels to verify that when text is long
enough to be chunked by the tokenizer, the showmodels result is still a
proper 3-tuple (translation, language, model) and not a malformed tuple
from incorrect concatenation.

Signed-off-by: JiangNan <[email protected]>

* Shorten test method name to fix build

Rename testLongTranslationWithShowmodels -> testShowmodelsChunked
as the previous name was too long for the test runner.

Signed-off-by: JiangNan <[email protected]>

---------

Signed-off-by: JiangNan <[email protected]>
2026-03-09 14:39:54 -04:00
davidmezzetti 69cc7538ac Remove coveralls build script workaround 2026-03-04 13:33:59 -05:00
davidmezzetti 0e3b7ff959 Bump version 2026-02-25 14:42:11 -05:00
davidmezzetti cd116aaa57 Add build script workaround while coveralls is down 2026-02-25 11:33:27 -05:00
davidmezzetti d1aa381e0e Add build script workaround while coveralls is down 2026-02-25 10:54:42 -05:00
davidmezzetti 96234c5754 Reformat docs 2026-02-24 17:36:25 -05:00
davidmezzetti 312f1653e7 Reformat docs 2026-02-24 17:33:52 -05:00
davidmezzetti 5cd7d7e407 Cache Agent Template, closes #1051 2026-02-24 17:08:54 -05:00
davidmezzetti 1a64d33823 Improve subindexes documentation 2026-02-24 17:07:36 -05:00
davidmezzetti 3073589ad6 Add deterministic setting to database functions closes #1048. Add ability to index database expressions #1049 2026-02-22 16:38:54 -05:00
davidmezzetti 2f2bd50027 Add ability to index database expressions, closes #1049 2026-02-22 16:37:11 -05:00
davidmezzetti f7380f64da Add store field to columns configuration, closes #1050 2026-02-22 16:36:08 -05:00
davidmezzetti a53b431492 Add support for custom SQL functions with DuckDB, closes #1047 2026-02-21 06:43:56 -05:00
davidmezzetti 2c937db56b Add sparse normalization info to docs 2026-02-21 06:43:24 -05:00
Jaepil Jeong ba0d1eaead Add BB25 normalization for sparse encoders (#1046)
* Add log-odds conjunction fusion for BB25 hybrid search

BB25 normalization outputs calibrated probabilities, but the existing
hybrid fusion uses convex combination which discards the Bayesian
probability semantics. This causes BB25 to regress on 4/5 BEIR datasets.

Add log-odds conjunction fusion (from "From Bayesian Inference to Neural
Computation") that correctly combines probability signals in logit space
with per-query dynamic calibration for dense cosine scores.

- scoring/normalize.py: Extract Bayesian method check into isbayes()
- scoring/base.py: Add default isbayes() returning False
- scoring/tfidf.py: Add isbayes() delegating to normalizer
- search/base.py: Add logodds(), convex(), rrf() fusion methods;
  dispatch based on isbayes()

BEIR nDCG@10 results (BB25+LogOdds vs Default):
  arguana +2.23, fiqa +2.03, scidocs +0.62, scifact +1.33, nfcorpus -1.96

* Extract Hybrid class for score fusion strategies

Move logodds, convex, and rrf fusion methods from Search into
a dedicated Hybrid class, following the same pattern as Normalize.

* Fix coding convention issues in Hybrid class for CI

- Fix black formatting: remove unnecessary parentheses, remove spaces around **
- Fix pylint too-many-branches: extract calibrate() method from logodds()
- Fix pylint unused-variable: rename score to _ in rrf()

* Add BB25 normalization for sparse encoders and fix IVFSparse topn bug

- Support `normalize: bb25` config for sparse encoder scoring, enabling
  Bayesian sigmoid calibration as an alternative to default linear
  normalization. Reuses existing Normalize.bayes() infrastructure.

- Fix dimension check in IVFSparse.topn(): use scores.shape[1] (number
  of data items) instead of scores.shape[0] (number of queries) for the
  argpartition kth bound check. The previous code caused ValueError when
  the number of centroids was less than nprobe.

* Add tests for BB25 sparse normalization and IVFSparse topn fix
2026-02-20 14:40:18 -05:00
davidmezzetti 89299926bd Add additional methods 2026-02-18 15:44:59 -05:00
davidmezzetti 00acd243b0 Code standardization and added tests #1041 2026-02-18 14:18:11 -05:00
Jaepil Jeong 48f0962a44 Add log-odds conjunction fusion for BB25 hybrid search (#1041)
* Add log-odds conjunction fusion for BB25 hybrid search

BB25 normalization outputs calibrated probabilities, but the existing
hybrid fusion uses convex combination which discards the Bayesian
probability semantics. This causes BB25 to regress on 4/5 BEIR datasets.

Add log-odds conjunction fusion (from "From Bayesian Inference to Neural
Computation") that correctly combines probability signals in logit space
with per-query dynamic calibration for dense cosine scores.

- scoring/normalize.py: Extract Bayesian method check into isbayes()
- scoring/base.py: Add default isbayes() returning False
- scoring/tfidf.py: Add isbayes() delegating to normalizer
- search/base.py: Add logodds(), convex(), rrf() fusion methods;
  dispatch based on isbayes()

BEIR nDCG@10 results (BB25+LogOdds vs Default):
  arguana +2.23, fiqa +2.03, scidocs +0.62, scifact +1.33, nfcorpus -1.96

* Extract Hybrid class for score fusion strategies

Move logodds, convex, and rrf fusion methods from Search into
a dedicated Hybrid class, following the same pattern as Normalize.

* Fix coding convention issues in Hybrid class for CI

- Fix black formatting: remove unnecessary parentheses, remove spaces around **
- Fix pylint too-many-branches: extract calibrate() method from logodds()
- Fix pylint unused-variable: rename score to _ in rrf()
2026-02-18 09:22:45 -05:00
davidmezzetti 1c181e4070 Update docs 2026-02-16 19:05:41 -05:00
davidmezzetti 371d5d8a19 Add test for bb25 2026-02-16 19:01:44 -05:00
davidmezzetti 834e4eb60d Fix cursor error with multithreaded keyword search, closes #1039 2026-02-16 19:01:27 -05:00
davidmezzetti fc579d77aa Update dtype to np.float32 2026-02-16 15:54:22 -05:00
Sigrid Jin (ง'̀-'́)ง oO 90e66075f6 Add Bayesian normalization "bb25" method for keyword scoring (#1037)
* Add Bayesian normalization for keyword scoring

* Add BB25 alias docs and references

* Align BB25 normalization with cognica candidate-set behavior
2026-02-16 15:53:26 -05:00
davidmezzetti 99339570cb Add new features to ngram tokenizer, closes #1038 2026-02-16 15:47:03 -05:00
davidmezzetti 38170a4ab1 Support ngram tokenization, closes #1017 2026-02-16 09:41:41 -05:00
Rin 5a66065b34 Escape single quotes in dynamic column names to prevent SQL injection (#1026) 2026-02-15 10:50:45 -05:00
davidmezzetti 090937a396 Bump version 2026-02-12 17:42:47 -05:00
davidmezzetti d6bd6fc4c6 Slight code improvement 2026-02-11 13:29:54 -05:00
davidmezzetti 90bee00f1d Add ability to store agent memory by session, closes #1025 2026-02-11 13:18:18 -05:00
davidmezzetti f013ca7d1d Workaround macOS test failure 2026-02-10 13:12:37 -05:00
davidmezzetti bfd1f13f2b Workaround macOS test failure 2026-02-10 12:20:32 -05:00
davidmezzetti f682fd949a Fix issue with latest version of FastAPI, closes #1022 2026-02-10 10:46:41 -05:00
davidmezzetti 4758907f3b Add input merging modes for language modeling training, closes #1021. Closes #1020 2026-02-10 09:42:23 -05:00
davidmezzetti b9cec19941 Update docs 2026-02-04 13:18:47 -05:00
davidmezzetti b7c9b156f6 Add example demonstrating how to use skill.md files, closes #1019 2026-02-04 13:18:39 -05:00
davidmezzetti 361b6fe2a5 Add example demonstrating how to use agents.md files, closes #1018 2026-02-04 13:18:21 -05:00
davidmezzetti 45e6080999 Update templates for agent memory 2026-02-04 13:17:49 -05:00
davidmezzetti 92461fe651 Add support for Agent memory, closes #1016 2026-01-30 16:22:01 -05:00
davidmezzetti 3a46f51f25 Add support for agents.md and skill.md. Closes #1014. Closes #1015 2026-01-30 15:35:19 -05:00
davidmezzetti 67543ab31c Update build script versions 2026-01-28 07:47:58 -05:00
davidmezzetti 14c440ac45 Bump version 2026-01-23 12:48:18 -05:00
davidmezzetti 7672f42743 httpx import at module level causes ModuleNotFoundError for Embeddings-only usage, closes #1012 2026-01-23 11:39:11 -05:00
davidmezzetti f360c2d98e Add minimal build workflow, closes #1013 2026-01-23 11:06:52 -05:00
davidmezzetti b4c80cf2e8 Bump torch version 2026-01-21 12:58:57 -05:00
davidmezzetti 831c3fd7d2 Bump version 2026-01-21 12:58:48 -05:00
davidmezzetti d3c498f316 Update documentation 2026-01-21 08:29:25 -05:00
davidmezzetti 001b97b0bf Add example notebook covering OpenCode LLM, closes #1011 2026-01-21 08:28:41 -05:00
davidmezzetti c48ecb3062 Add OpenCode LLM, closes #1010 2026-01-19 21:14:37 -05:00
davidmezzetti f7d5790d07 Update Faiss workaround code #1009 2026-01-16 04:46:18 -05:00
davidmezzetti 5e3492799b Update Faiss workaround code #1009 2026-01-15 20:56:19 -05:00
davidmezzetti 2c3a21490a Update imports 2026-01-15 17:42:44 -05:00
davidmezzetti 846cf2ddc7 Update notes on KMP_DUPLICATE_LIB_OK, closes #1009 2026-01-15 16:18:10 -05:00
davidmezzetti ceb7a4a8f8 Add KMP_DUPLICATE_OK workaround for Faiss OMP Error #1009 2026-01-15 16:06:04 -05:00
davidmezzetti 79e2f9bdef Add video link 2026-01-15 14:39:33 -05:00
davidmezzetti 8d8b29e41c Fix links 2026-01-15 13:21:54 -05:00
davidmezzetti bd2a516eb4 Add example notebook showing how to finetune LLMs, closes #1008 2026-01-15 12:52:07 -05:00
davidmezzetti d4e8ee41f4 Update baseball application #1003 2026-01-11 10:30:34 -05:00
davidmezzetti cdf9a40c8e Update baseball application #1003 2026-01-11 10:29:38 -05:00
davidmezzetti a6c64a6944 Add Tokenizer documentation 2026-01-11 09:38:44 -05:00
davidmezzetti 7132f63c46 Add additional tokenization methods for keyword search, closes #1006 2026-01-11 09:04:36 -05:00
davidmezzetti 1ff636de4a Add RAG video link 2026-01-08 15:27:04 -05:00
davidmezzetti 2a63caf83e Reformat code 2026-01-05 12:05:33 -05:00
davidmezzetti 86e768bccb Load instruction prompts for Sentence Transformers models, closes #1004 2026-01-05 12:03:48 -05:00
davidmezzetti 995428d96c Update application 2025-12-24 10:06:32 -05:00
davidmezzetti 7b97ddf9d8 Update application 2025-12-24 05:38:00 -05:00
davidmezzetti 172f804c1b Update application 2025-12-23 20:36:51 -05:00
davidmezzetti 17b4660abe Fix Baseball Sample Application, closes #1003 2025-12-23 19:20:07 -05:00
davidmezzetti 8c22567d10 Bump version 2025-12-22 20:34:03 -05:00
davidmezzetti 1d7b6a98c9 Sync parameter with LLM pipeline default #998 2025-12-15 13:29:46 -05:00
davidmezzetti 1545901d27 Update notebook 2025-12-15 13:29:25 -05:00
davidmezzetti c4b2bc4251 Add documentation for MUVERA vector settings 2025-12-12 21:07:40 -05:00
davidmezzetti 6021194ac9 Update notebook 2025-12-12 14:46:15 -05:00
davidmezzetti 9d4772bb65 Clean notebook 2025-12-12 14:17:48 -05:00
davidmezzetti a8507d024d Add notebook covering any search method with the RAG Pipeline, closes #1002 2025-12-12 14:11:41 -05:00
davidmezzetti 0c2eab7098 Update notebooks 2025-12-12 10:53:35 -05:00
davidmezzetti 4aa9db69fc Update model paths 2025-12-12 10:46:36 -05:00
davidmezzetti aca56cfe53 Modernize example notebooks, closes #1001 2025-12-12 10:31:27 -05:00
davidmezzetti 203855a9d7 Move LLM and RAG docs into their own folder 2025-12-11 21:31:10 -05:00
davidmezzetti 861545a1ed Update test 2025-12-11 21:30:52 -05:00
davidmezzetti 92d02d748d Add support for any callable search function in RAG pipeline, closes #1000 2025-12-11 20:49:57 -05:00
davidmezzetti 75c4f54f63 Add new LLM default parameters, closes #998. Closes #999. 2025-12-11 20:47:45 -05:00
davidmezzetti 5d6d3f7a6b Update deprecated transformers torch_dtype parameter, closes #997 2025-12-11 20:42:46 -05:00
davidmezzetti 48584abdb4 Update documentation 2025-12-10 18:31:46 -05:00
davidmezzetti 1c4f041b91 Update documentation 2025-12-10 17:52:38 -05:00
davidmezzetti 4ba611760d Update documentation 2025-12-10 17:51:27 -05:00
davidmezzetti c61e18a216 Update documentation 2025-12-10 17:47:29 -05:00
davidmezzetti fb257a2e5e Update documentation 2025-12-10 17:46:30 -05:00
davidmezzetti c26a61dcb6 Update documentation 2025-12-10 17:45:05 -05:00
davidmezzetti b5b3922464 Update documentation 2025-12-03 08:32:30 -05:00
davidmezzetti 441d0eabd7 Add Workflow Quickstart Example, closes #996 2025-12-01 18:44:14 -05:00
davidmezzetti 4d6c0ecc47 Update documentation to use more current LLMs, closes #995 2025-11-30 14:51:15 -05:00
davidmezzetti dd83a40197 model_id is not properly passed with current version of smolagents, closes #993 2025-11-30 14:50:35 -05:00
davidmezzetti 58664444a1 args and kwargs should be ignored when inspecting function parameters in agents, closes #994 2025-11-30 14:50:10 -05:00
davidmezzetti 0a401cb9a2 Add Agent Quickstart Example, closes #992 2025-11-30 14:49:08 -05:00
davidmezzetti d3d26a5ebd Add RAG Quickstart Example, closes #991 2025-11-29 07:22:16 -05:00
davidmezzetti d75be702dd Add support for wildcards in scoring term search, closes #990 2025-11-29 06:52:41 -05:00
davidmezzetti 60755501f5 Add Textractor as top level import, closes #989 2025-11-28 08:10:35 -05:00
davidmezzetti e0f8a9404f Upgrade GLiNER, closes #988 2025-11-25 17:23:30 -05:00
davidmezzetti 26ac43df1c Bump version 2025-11-21 17:03:15 -05:00
davidmezzetti b8da57eb88 Bump torch version 2025-11-21 17:02:55 -05:00
davidmezzetti d3a5217153 Limit GLiNER to ignore latest release, closes #984 2025-11-19 08:29:13 -05:00
davidmezzetti 99e3457b1f Fix compatibility with latest version of Faiss, closes #986 2025-11-18 13:28:46 -05:00
davidmezzetti b870a3265a Fix compatibility with latest version of smolagents, closes #985 2025-11-18 11:33:37 -05:00
davidmezzetti 81c152c5ee Update build script 2025-11-18 10:49:35 -05:00
davidmezzetti 90efb5c349 Update documentation for Agents 2025-11-18 08:54:37 -05:00
davidmezzetti 351702249b Workaround build script error with GLiNER #984 2025-11-14 16:11:01 -05:00
davidmezzetti bb37634f8c Update llama.cpp vectors to support default length and batch parameters, closes #983 2025-11-14 09:28:57 -05:00
davidmezzetti 594145840f Support stripthink in streaming LLM responses, closes #981 2025-11-10 16:32:37 -05:00
davidmezzetti 4447053dd4 Add stripthink parameter to LLM API endpoint, closes #980 2025-11-10 16:32:11 -05:00
davidmezzetti 8794d714cc Add tuples option to Segmentation pipeline, closes #979 2025-11-07 14:26:03 -05:00
davidmezzetti 62a7ade776 Update deprecated parameter for HFTrainer, closes #978 2025-11-07 09:26:54 -05:00
davidmezzetti 8a01cd2c06 Bump version 2025-11-04 19:07:02 -05:00
davidmezzetti 02bae7ddf1 Bump torch version 2025-11-04 19:06:53 -05:00
davidmezzetti 1f8e9c5ddb Add GGUF example to low level API example #973 2025-11-01 04:16:29 -04:00
davidmezzetti d64c8d8f27 Add GGML ANN documentation 2025-10-31 22:31:31 -04:00
davidmezzetti fc69c82b94 Update build script 2025-10-31 21:47:39 -04:00
davidmezzetti 75f68c375d Remove debug statement 2025-10-31 21:28:09 -04:00
davidmezzetti e715b3b4f6 Update GGML cpu call 2025-10-31 20:40:01 -04:00
davidmezzetti ce3bdfaee6 Update build script 2025-10-31 12:19:32 -04:00
davidmezzetti 6fa604213b Update build script 2025-10-31 10:37:10 -04:00
davidmezzetti 536a724764 Update build script 2025-10-31 10:14:59 -04:00
davidmezzetti de3fee46e6 Update build script 2025-10-31 07:21:04 -04:00
davidmezzetti 0a074ae559 Update build script 2025-10-30 21:32:02 -04:00
davidmezzetti f4f267d449 Update build script 2025-10-30 18:13:10 -04:00
davidmezzetti cf45a400ce Add GGML ANN, closes #975 2025-10-30 17:53:44 -04:00
davidmezzetti a07b88f003 Fix issue with False ANN settings, closes #976 2025-10-30 17:52:40 -04:00
davidmezzetti 3bc7890360 Add example notebook demonstrating how to access low level vector APIs, closes #973 2025-10-22 13:31:02 -04:00
davidmezzetti e5519d25c3 Update docs 2025-10-17 09:13:02 -04:00
davidmezzetti e662a631e2 Skip quantization tests for macOS 2025-10-17 08:11:05 -04:00
davidmezzetti fb5c3cc468 Update setup.py requirements 2025-10-17 07:34:04 -04:00
davidmezzetti 1d8c941d1b Update setup.py requirements 2025-10-17 07:31:47 -04:00
davidmezzetti 13715059dc Remove build script workaround, closes #970 2025-10-17 07:24:39 -04:00
davidmezzetti e6e1d57ac4 Add quantization support to Torch ANN, closes #971 2025-10-17 07:24:05 -04:00
davidmezzetti 2c45420a70 Pin mcpadapt==0.1.16 until upstream issue resolved #970 2025-10-13 15:49:19 -04:00
davidmezzetti 8dcab1addc Add support for Safetensors storage to NumPy/Torch ANN backend, closes #969 2025-10-13 15:23:03 -04:00
davidmezzetti 7c96fd93d9 Update build script 2025-10-08 13:10:28 -04:00
davidmezzetti 31b6b767fd Update build script 2025-10-08 13:04:41 -04:00
davidmezzetti 612d1ad2f8 Update build script 2025-10-08 12:12:08 -04:00
davidmezzetti f4d00c75a5 Update example 2025-10-08 10:13:01 -04:00
davidmezzetti 0d96790a64 Add GraphRAG example notebook with wikipedia and gpt-oss, closes #967 2025-09-17 16:17:15 -04:00
davidmezzetti 9a1a1e400c Update LLM stripthink parameter to support gpt-oss patterns, closes #966 2025-09-17 16:16:34 -04:00
davidmezzetti a543b028ef Syntax update 2025-09-17 07:59:20 -04:00
davidmezzetti 8ae88a6405 Bump version 2025-09-15 14:32:24 -04:00
davidmezzetti 97e4bdb2b4 Update build script versions 2025-09-11 16:35:52 -04:00
davidmezzetti 741f39495e Update build script versions 2025-09-11 16:29:51 -04:00
davidmezzetti 646af6ba87 Support older versions of Python without extraction filters #965 2025-09-11 13:30:28 -04:00
davidmezzetti fc15901cee Update build scripts 2025-09-11 13:29:38 -04:00
davidmezzetti 97f3175ddf Update build scripts 2025-09-11 12:57:22 -04:00
davidmezzetti 3a4457f563 Update build scripts 2025-09-11 12:49:26 -04:00
davidmezzetti d523a860fa Update build scripts 2025-09-11 12:47:34 -04:00
davidmezzetti e7e44c00e6 Update build script Python setup 2025-09-11 12:22:00 -04:00
davidmezzetti a5eca34c98 Update build script Python setup 2025-09-11 12:19:32 -04:00
davidmezzetti e09c205d70 Update build script Python setup 2025-09-11 12:09:17 -04:00
davidmezzetti 6bef6869f5 Update version 2025-09-11 11:49:50 -04:00
davidmezzetti a5306ae5d7 Code cleanup 2025-09-11 11:48:59 -04:00
davidmezzetti 303a257615 Additional checks for tar file extraction, closes #965 2025-09-11 11:41:09 -04:00
davidmezzetti f082bf2a27 Update build script for macOS builds #964 2025-09-02 14:17:36 -04:00
davidmezzetti 4c698b3638 Update build script for macOS builds, closes #964 2025-09-02 14:15:56 -04:00
davidmezzetti 4e33678099 Update docs 2025-09-02 13:56:37 -04:00
davidmezzetti 3734404449 Update documentation 2025-08-29 15:05:38 -04:00
davidmezzetti ffa4543b2f Bump version 2025-08-28 21:46:43 -04:00
davidmezzetti 5174079c93 Bump torch version 2025-08-28 21:46:35 -04:00
davidmezzetti 9ef94c8c79 Remove build workaround, closes #962 2025-08-28 15:13:50 -04:00
davidmezzetti ba15148b83 Add 9.0 article link 2025-08-28 13:25:15 -04:00
davidmezzetti 1f5a352261 Add exponential http backoff to work around constant HF Hub 429 errors 2025-08-28 09:38:59 -04:00
davidmezzetti 1f5f9cd406 Workaround build issue with latest version of Chonkie #962 2025-08-28 08:34:39 -04:00
davidmezzetti 549632b461 Add what's new in txtai 9.0 notebook, closes #956 2025-08-27 18:18:29 -04:00
davidmezzetti c4152ff4e1 Update benchmarks script to support similarity and reranking pipelines, closes #961 2025-08-27 15:00:44 -04:00
davidmezzetti b8980bc5be Add Reranker pipeline, closes #960 2025-08-27 15:00:12 -04:00
davidmezzetti 0e54ad3c3f Add ability to merge late interaction vectors into fixed dimensional MUVERA vectors, closes #952 2025-08-27 14:58:05 -04:00
davidmezzetti 34e468e475 Remove build script workaround, closes #957 2025-08-19 18:11:54 -04:00
davidmezzetti 28273d0369 Fix issue with device call 2025-08-18 16:29:48 -04:00
davidmezzetti c68c136b2d Add build script workaround for LiteLLM issue #957 2025-08-18 15:58:45 -04:00
davidmezzetti 6fcdcb1e38 Update benchmark scripts to support Similarity pipeline, closes #955 2025-08-18 14:19:30 -04:00
davidmezzetti 2866dd962e Update similarity pipeline to support late interaction models, closes #953 2025-08-18 14:15:28 -04:00
davidmezzetti 1b1ab4c9ea Add support for late interaction models, closes #954 2025-08-18 14:13:59 -04:00
davidmezzetti ad55344f26 Change default behavior for pickle serialization to disabled, closes #949 2025-08-13 12:20:41 -04:00
davidmezzetti 2956bd8789 Modify LiteLLM path detection logic, closes #947 2025-08-06 09:17:29 -04:00
davidmezzetti b53c966fa7 Change sparse vector normalization logic, closes #946 2025-08-05 18:26:49 -04:00
davidmezzetti cd784436ef Track indexing progress in benchmark script 2025-08-05 16:16:36 -04:00
davidmezzetti 5cf22c648d Update comment 2025-08-01 16:14:50 -04:00
davidmezzetti f04a43578b IVFSparse improvements, closes #943 2025-07-19 08:16:15 -04:00
davidmezzetti 944ef19276 Update comment 2025-07-16 16:35:22 -04:00
davidmezzetti da5baa2479 Require sparse keyword/vector scores to be greater than 0, closes #941 2025-07-16 16:32:11 -04:00
davidmezzetti 9b935a24d1 Change default sparse vector model, closes #940 2025-07-16 16:31:46 -04:00
davidmezzetti 6cf12b97a0 Limit pgsparse input vectors to 1000 non-zero elements, closes #939 2025-07-16 16:30:58 -04:00
davidmezzetti 1edf3ecc4c Modify pgvector ann index to build after data load, closes #938 2025-07-16 16:24:28 -04:00
davidmezzetti 399f584d44 Update comment 2025-07-16 16:22:51 -04:00
davidmezzetti dc57d6bf0d Add test for embeddings shortcuts 2025-07-14 08:31:45 -04:00
davidmezzetti e765be3f6c Refactor of ann and vectors packages for sparse vectors. Closes #930. Closes #934. Closes #935. Closes #936. Closes #937. 2025-07-14 07:48:23 -04:00
davidmezzetti af264bd0bb Update test 2025-07-08 22:13:45 -04:00
davidmezzetti db60bd76e6 Add IVFFlat indexing for sparse vectors, closes #929 2025-07-08 21:44:35 -04:00
davidmezzetti 69145bf98e Ensure scores returned from scoring module are floats and not NumPy values, closes #933 2025-07-08 21:43:35 -04:00
davidmezzetti 9c3bf13d39 Improve hybrid scoring algorithm, closes #931 2025-07-08 21:42:19 -04:00
davidmezzetti a1df111bb8 Pass kwargs to msgpack serializer , closes #932 2025-07-08 21:41:39 -04:00
davidmezzetti e9fa455206 Remove build script workaround, closes #928 2025-07-05 06:40:20 -04:00
davidmezzetti 23e37b4b51 Build script workaround #928 2025-07-04 10:03:50 -04:00
davidmezzetti 2549c6598d Update test 2025-07-04 09:33:03 -04:00
davidmezzetti 5f774b5fd9 Update sentence transformers pool call to use v5.0 features, closes #927 2025-07-04 09:28:20 -04:00
davidmezzetti 2d0ae9c749 Bump version 2025-07-04 09:28:04 -04:00
davidmezzetti fdd37c9afa Bump version 2025-07-04 09:27:49 -04:00
davidmezzetti 6ca8a61856 Update test to workaround HF Hub HTTP 429 issues, closes #926 2025-07-04 09:27:20 -04:00
davidmezzetti d9c50c84b7 Add sparse vector scoring, closes #924. Update default Embeddings parameters, closes #925 2025-07-04 09:26:36 -04:00
davidmezzetti 397ed4d321 Update documentation 2025-06-29 17:03:21 -04:00
davidmezzetti 0aa285848d Update documentation 2025-06-28 08:12:56 -04:00
davidmezzetti 10c524c56b Update documentation 2025-06-28 08:06:08 -04:00
davidmezzetti dd8ff3078a Only add body tags if they don't already exist, closes #919 2025-06-24 09:24:50 -04:00
davidmezzetti d25209fd89 Add example notebook for Medical RAG Research with txtai, closes #921 2025-06-23 16:59:59 -04:00
davidmezzetti 255164992a Add parameter to strip thinking tags from LLM outputs, closes #920 2025-06-23 16:58:35 -04:00
davidmezzetti 7fb9c9fd29 Update Slack link 2025-06-12 09:26:55 -04:00
davidmezzetti fa924845e8 Remove onnxxmltools workaround, closes #916 2025-06-10 13:03:38 -04:00
davidmezzetti fa6a0fdd3c Bump version 2025-06-10 12:41:05 -04:00
davidmezzetti 01b667ad7e Bump torch version 2025-06-10 12:40:56 -04:00
davidmezzetti 34ba105110 Fix import error with latest version of onnx, closes #907 2025-06-10 08:36:51 -04:00
davidmezzetti 77eb913d12 Update docs 2025-06-05 13:41:20 -04:00
davidmezzetti 7fffd5e435 Update build script #907 2025-05-30 12:26:01 -04:00
davidmezzetti 24b0b7ceca Fix issue with latest version of smolagents, closes #913 2025-05-30 11:45:22 -04:00
davidmezzetti 61fa8a3f99 Fix issue with max length and LLM pipeline, closes #912 2025-05-30 11:22:36 -04:00
davidmezzetti a55460a9cb Update build script 2025-05-26 22:25:54 -04:00
davidmezzetti 71cf97d104 Fix issue with max length and summary pipeline, closes #912 2025-05-26 21:42:12 -04:00
davidmezzetti 484b366608 Handle GrandCypher API change, closes #909 2025-05-26 20:15:48 -04:00
davidmezzetti 1777f6aca7 Build script workaround #907 2025-05-15 15:58:25 -04:00
davidmezzetti 203cbecc60 Fix bug with latest version of smolagents, closes #906 2025-05-15 09:27:47 -04:00
davidmezzetti d34fb4b2e2 Update build script 2025-05-15 08:53:30 -04:00
davidmezzetti c080f1d4b0 Revert build script workaround, closes #902 2025-05-05 08:55:22 -04:00
davidmezzetti 6ae346e736 Encoding issue with latest version of LiteLLM #902 2025-04-29 11:30:47 -04:00
davidmezzetti f71fa1fd5e Add kwargs to labels/similarity pipeline, closes #882 2025-04-29 09:31:30 -04:00
davidmezzetti 6d0891b4fa Update test 2025-04-23 11:23:52 -04:00
davidmezzetti 80a8076c2b Update docs 2025-04-23 09:22:25 -04:00
davidmezzetti a5468af853 Update tagline to the all-in-one AI framework, closes #901 2025-04-23 09:15:37 -04:00
davidmezzetti 529dc446f9 Update tagline to the all-in-one AI framework, closes #901 2025-04-23 09:14:34 -04:00
davidmezzetti 8917c0dab0 Update docs 2025-04-15 12:34:09 -04:00
davidmezzetti 80811ef9f3 Bump version 2025-04-14 20:19:02 -04:00
davidmezzetti 97a5192cdf Add support for MCP servers to Agent Framework, closes #898 2025-04-12 11:13:26 -04:00
davidmezzetti 9647c7e918 Add Model Context Protocol (MCP) Support, closes #892 2025-04-11 15:03:14 -04:00
davidmezzetti 19a4b7571f Update test 2025-04-11 11:30:31 -04:00
davidmezzetti 1d1fc36163 Update docs 2025-04-11 10:28:29 -04:00
davidmezzetti b18854f788 Migrate to smolagents, closes #890 2025-04-11 09:38:19 -04:00
davidmezzetti 408a053001 Fix test that was using a method deprecated in Python 3.10 2025-04-08 12:04:06 -04:00
davidmezzetti a6d6231d74 Require Python 3.10+, closes #897 2025-04-08 09:21:31 -04:00
davidmezzetti a3f0896961 Update dependency version 2025-04-07 18:43:05 -04:00
davidmezzetti 642ef2307a Image encoder issue fixed upstream #895 2025-04-04 08:22:33 -04:00
davidmezzetti 6368af1591 Lazy load list of translation models, closes #896 2025-04-04 08:17:33 -04:00
davidmezzetti 6a10aa88d0 Fix bug introduced with Pillow 11.2, closes #895 2025-04-01 13:05:58 -04:00
davidmezzetti 1f65a64dc3 Update docs 2025-04-01 11:05:19 -04:00
davidmezzetti c50d8fd96d Update docs 2025-04-01 10:44:14 -04:00
davidmezzetti 04795b614b Update docs 2025-03-31 13:41:13 -04:00
davidmezzetti a78b3b298f Increase default HF Hub timeout in build script 2025-03-22 09:28:14 -04:00
davidmezzetti 20ac850ec9 Update docs 2025-03-21 22:27:31 -04:00
davidmezzetti 15ee408db8 Modify test vision model, closes #891 2025-03-21 12:21:40 -04:00
davidmezzetti e97237ab29 Update cached_file exception handling, closes #889 2025-03-21 12:19:20 -04:00
davidmezzetti 15bb6346cf Add note on Model Context Protocol to docs 2025-03-21 10:18:33 -04:00
davidmezzetti a211f0e1ca Fix issue with MessageRole Enums and LLM pipeline, closes #888 2025-03-14 14:38:09 -04:00
davidmezzetti 76d39bfe10 Update docs 2025-03-14 13:08:05 -04:00
davidmezzetti 675eea9b92 Try latest version of llama-cpp-python 2025-03-13 10:52:50 -04:00
davidmezzetti 1bc1c59786 Update docs 2025-03-13 09:25:31 -04:00
davidmezzetti d902ee996b Bump version 2025-03-11 14:23:41 -04:00
davidmezzetti 3517704d1a Update docs 2025-03-11 08:42:56 -04:00
davidmezzetti 3ddb3e12ba Update docs 2025-03-05 10:59:51 -05:00
davidmezzetti fa2f114dee Build script workaround for llama-cpp-python error 2025-03-04 21:34:39 -05:00
davidmezzetti 4a1aa4d0f6 Build script workaround for llama-cpp-python error 2025-03-04 19:17:14 -05:00
davidmezzetti e7cafe3fd7 Update comment 2025-03-04 19:11:28 -05:00
davidmezzetti bbf474314b Add example notebook showing how to use OpenAI compatible API, closes #887 2025-03-04 15:55:02 -05:00
davidmezzetti 13ab0c3b9e Add OpenAI API compatible endpoint to API, closes #883 2025-03-04 15:54:30 -05:00
davidmezzetti 186e58a114 Add support for vision models to HF LLM pipeline, closes #884 2025-03-04 15:53:27 -05:00
davidmezzetti 34fa089e68 Add texttospeech pipeline to API, closes #552 2025-03-04 15:51:44 -05:00
davidmezzetti 679e0cef89 Add encoding parameter to TextToSpeech pipeline, closes #885 2025-03-04 15:50:37 -05:00
davidmezzetti 6301617cd8 Add support for input streams to Transcription pipeline, closes #886 2025-03-04 15:49:53 -05:00
davidmezzetti 1524b74a6b Add upload endpoint to API, closes #659 2025-03-04 15:49:03 -05:00
davidmezzetti 437ee1c15b Update docs 2025-02-26 09:51:06 -05:00
davidmezzetti 13ec1e10fa Update docs 2025-02-25 18:54:42 -05:00
davidmezzetti a9833d0d67 Update docs 2025-02-25 08:16:50 -05:00
davidmezzetti 04d4bc43aa Add docs for observability, closes #869 2025-02-24 22:12:49 -05:00
davidmezzetti f880793ae3 Reset HFTrainer #879 2025-02-22 17:40:32 -05:00
davidmezzetti ba552d5a3f Set deterministic behavior for cuDNN in HFTrainer #879 2025-02-22 10:42:00 -05:00
davidmezzetti 1a9f5eaded Default full_determinism to True in HFTrainer, closes #879 2025-02-22 07:38:08 -05:00
davidmezzetti a1a7d34cd8 Embeddings index checkpointing, closes #695 2025-02-19 16:44:37 -05:00
davidmezzetti 8a3ed27bbb Fix bug with latest version of Transformers and model registry, closes #878 2025-02-17 15:26:02 -05:00
davidmezzetti a92bb73c9c Add similar query clause to graph queries, closes #875 2025-02-17 13:07:42 -05:00
davidmezzetti 4d92dfc965 Update method signature 2025-02-12 11:59:23 -05:00
davidmezzetti 1d077898ca Bump version 2025-02-12 11:57:05 -05:00
davidmezzetti 53f5af52ad Ensure staticvectors is installed before calling method, closes #876 2025-02-12 07:33:14 -05:00
davidmezzetti 64c1a5c5c7 Bump version 2025-02-11 16:15:32 -05:00
davidmezzetti b72b04a972 Update documentation 2025-02-11 12:01:01 -05:00
davidmezzetti a68a1338eb Add example notebook for RAG Chunking, closes #874 2025-02-11 12:00:48 -05:00
davidmezzetti cc5d16df88 Add example notebook for Entity Extraction with GLiNER, closes #873 2025-02-11 12:00:28 -05:00
davidmezzetti 870c7007f6 Improve parsing of table text in HTML to Markdown pipeline, closes #872 2025-02-11 08:54:01 -05:00
davidmezzetti 7dc1e4bb5f Update test 2025-02-07 09:01:23 -05:00
davidmezzetti 53fa7ad872 Update textractor pipeline documentation with details on text splitting/chunking 2025-02-07 08:59:57 -05:00
davidmezzetti d7f8210d16 Remove build script workaround, closes #852 2025-02-07 06:54:38 -05:00
davidmezzetti bd16c6e25c Bump Torch CPU version 2025-02-07 06:54:12 -05:00
davidmezzetti f52ce51413 Word vector model improvements, closes #868 2025-02-05 13:23:01 -05:00
davidmezzetti 2cd8989183 Remove dead code 2025-02-05 13:22:30 -05:00
davidmezzetti 61ca27a128 Replace python-louvain library with networkx equivalent, closes #867 2025-02-04 19:27:23 -05:00
davidmezzetti 5049f0447a Update build script 2025-02-04 12:35:20 -05:00
davidmezzetti ce36fef822 Build script workaround 2025-02-04 09:25:11 -05:00
davidmezzetti bf32498a79 Add semantic chunking, closes #812 2025-02-04 07:45:25 -05:00
davidmezzetti 6e55f7a862 Add GLiNER example to docs 2025-02-04 07:42:33 -05:00
davidmezzetti 44fb2f9d9f Detect graph queries and route to graph index, closes #865 2025-02-02 09:21:09 -05:00
davidmezzetti 2b6aa5f363 Add GLiNER #862 2025-01-31 11:01:19 -05:00
davidmezzetti 13bafb01c6 Add support for GLiNER models, closes #862 2025-01-31 10:37:02 -05:00
davidmezzetti ac4c0583e8 Update build script 2025-01-30 10:40:51 -05:00
davidmezzetti e2e81cd2e3 Handle empty token list with word vectorization, closes #861 2025-01-30 09:56:56 -05:00
davidmezzetti fb56af8973 Update build script 2025-01-30 07:41:04 -05:00
davidmezzetti 8fb3aba425 Update method documentation, closes #860 2025-01-29 19:57:24 -05:00
davidmezzetti 986da4700a Check for multiple exception types #859 2025-01-27 12:34:28 -05:00
davidmezzetti 5887f5f247 Add missing dependency #857 2025-01-27 11:35:14 -05:00
davidmezzetti f79d8062ae Replace fasttext and pymagnitude with staticvectors. Closes #857. Closes #858. Closes #859 2025-01-27 11:17:51 -05:00
davidmezzetti 12aa955b77 Update build script 2025-01-23 20:34:32 -05:00
davidmezzetti 99df8c0901 Update documentation 2025-01-20 05:21:03 -05:00
davidmezzetti dca693828b Update TextToSpeech pipeline 2025-01-16 22:15:30 -05:00
davidmezzetti 77649d5f30 Update documentation for TextToSpeech pipeline 2025-01-16 12:58:50 -05:00
davidmezzetti 8fc52f23ba Add Kokoro TTS support to TextToSpeech pipeline, closes #854 2025-01-16 12:24:43 -05:00
davidmezzetti 39609f3ef9 Add new methods for audio signal processing, closes #855 2025-01-16 12:24:07 -05:00
davidmezzetti ece8e6f8f2 Update build script 2025-01-12 11:26:32 -05:00
davidmezzetti ac5d04f86b Add notebook to documentation 2025-01-12 11:18:14 -05:00
davidmezzetti 91cee347f5 Pin transformers version in build script to work around transformers bug #852 2025-01-12 10:45:20 -05:00
davidmezzetti f9b9efa5f6 Update build script 2025-01-12 10:23:42 -05:00
davidmezzetti d5069b9c39 Update build script 2025-01-12 10:21:17 -05:00
davidmezzetti 351d6f8a80 Update build script 2025-01-12 10:14:56 -05:00
davidmezzetti 0c8a2627ff Update build script 2025-01-12 10:11:43 -05:00
davidmezzetti 532a87049b Update build script 2025-01-12 10:07:50 -05:00
davidmezzetti 6a1664db67 Add notebook that analyzes NeuML LinkedIn posts, closes #851 2025-01-12 09:59:22 -05:00
davidmezzetti 5178f92767 Bump version 2025-01-09 15:54:00 -05:00
davidmezzetti 05da209b78 Add documentation for copyattributes 2025-01-09 13:18:03 -05:00
davidmezzetti 4e5331e641 Support pulling attribute data in graph.scan, closes #849 2025-01-09 13:14:50 -05:00
davidmezzetti 80db3a9a85 Graph RAG - Add extra attributes, closes #684 2025-01-09 13:13:02 -05:00
davidmezzetti c7e0fe3f99 Support graph=True in embeddings config, closes #848 2025-01-09 13:11:34 -05:00
davidmezzetti 1352040add Update RAG notebooks to add clarifying notes on LLM inference, closes #847 2025-01-09 07:28:53 -05:00
davidmezzetti 2d8cf5d80d Add vectors argument to Model2Vec vectors, closes #846 2025-01-06 20:33:44 -05:00
davidmezzetti 38520439b9 Update documentation 2025-01-03 09:05:05 -05:00
davidmezzetti dd92c18663 Update notebook and documentation 2025-01-02 13:02:42 -05:00
Igor Ribeiro Lima 991ea6ac11 Enhanced Docs: LLM Embedding Examples (#844)
* enhance documentation

* Address PR comment

* improvement and enhancmenet

* update notebook

* Address PR comment
2025-01-02 10:51:01 -05:00
davidmezzetti 2e0dfb36d9 Update comments 2024-12-28 14:14:22 -05:00
davidmezzetti fc611ed228 Remove pillow from build script, closes #800 2024-12-28 05:51:31 -05:00
davidmezzetti 65a8316de5 Vector encoding using multiple-GPUs, closes #541 2024-12-21 20:30:55 -05:00
davidmezzetti 34ffc9723d Update powered by 2024-12-21 09:16:11 -05:00
davidmezzetti 522760447d Ensure generated datetimes are in UTC, closes #840 2024-12-21 07:16:27 -05:00
davidmezzetti 952a7575b7 Add defaultrole to LLM pipeline, closes #841 2024-12-19 07:28:51 -05:00
davidmezzetti 9bd2da7213 Update test 2024-12-17 13:01:16 -05:00
davidmezzetti ec5f33b1ea Update test to run on macOS 2024-12-17 12:23:14 -05:00
davidmezzetti 5d7292048b Update powered by section with latest apps 2024-12-15 09:09:56 -05:00
davidmezzetti bb851a1dc0 Bump version 2024-12-10 12:36:54 -05:00
davidmezzetti 5e56dade9c Add support for halfvec and bit vector types with PGVector ANN, closes #839 2024-12-10 07:02:44 -05:00
davidmezzetti d39b85e04b Bound ANN hamming scores between 0.0 and 1.0, closes #838 2024-12-10 06:59:56 -05:00
davidmezzetti 6cc886aaad RDBMS graph.delete tests and upgrade graph dependency, closes #837 2024-12-10 06:57:06 -05:00
davidmezzetti 0354e2bef3 Move create schema calls into their own transaction #831 2024-12-08 06:49:46 -05:00
davidmezzetti cab131e92a Fix bug with NetworkX.hasedge method, closes #834 2024-12-08 06:46:32 -05:00
davidmezzetti 69aa23c462 Add docs for embeddings context manager #832 2024-12-08 06:45:04 -05:00
davidmezzetti e215ea13bb Add Embeddings context manager, closes #832 2024-12-06 17:48:41 -05:00
davidmezzetti e7aa46a1f0 Fix resource issues with embeddings indexing components backed by databases, closes #831 2024-12-06 17:23:46 -05:00
davidmezzetti 89410d3661 Change schema statements to use bind parameters #829 2024-12-05 13:15:52 -05:00
davidmezzetti 26bd35dc02 Add HTML normalization rules to Docling #814 2024-12-05 08:39:48 -05:00
davidmezzetti 3f7bb71a3e Persist embeddings components to specified schema, closes #829 2024-12-04 15:18:05 -05:00
davidmezzetti 92489ac89a Update build script and test 2024-12-03 18:32:02 -05:00
davidmezzetti b05abd20f3 Update test 2024-12-03 18:09:38 -05:00
davidmezzetti c6cd565518 Update build script 2024-12-03 17:52:43 -05:00
davidmezzetti 05ae9ebcb2 Update build script 2024-12-03 17:33:13 -05:00
davidmezzetti 4fe7877dd9 Update build script 2024-12-03 16:08:43 -05:00
davidmezzetti 1aa6c506ca Skip Docling tests for macOS due to MPS issues 2024-12-03 14:52:34 -05:00
davidmezzetti 9efc9ba070 Add text extraction with Docling, closes #814. Refactor Textractor pipeline into multiple pipelines, closes #828 2024-12-03 14:27:49 -05:00
davidmezzetti 5fdbc90d24 Autodetect Model2Vec model paths, closes #822. Refactor vectors package, closes #826. 2024-12-01 08:27:09 -05:00
davidmezzetti 4b5164beca Fix issue with calling cached_file for local directories, closes #825 2024-12-01 08:19:24 -05:00
davidmezzetti cb22635bff Fix memory issue with llama.cpp LLM pipeline, closes #824 2024-11-30 10:38:47 -05:00
davidmezzetti 7edc7aa184 Add parameter to disable text cleaning in Segmentation pipeline, closes #823 2024-11-30 10:37:52 -05:00
davidmezzetti 350087ee1d Cloud storage improvements, closes #821 2024-11-27 16:42:25 -05:00
davidmezzetti 2e8450d816 Update comments 2024-11-27 16:32:25 -05:00
davidmezzetti 384201d4c8 Update documentation 2024-11-25 16:18:33 -05:00
davidmezzetti 51aab3eb26 Add an example notebook for autonomous agents, closes #820 2024-11-25 15:54:21 -05:00
davidmezzetti 0f916d30e2 Documentation updates 2024-11-24 09:36:19 -05:00
davidmezzetti ff4d4dac14 Update build script and test 2024-11-23 07:42:17 -05:00
David Mezzetti f840ed7625 Merge pull request #819 from eltociear/patch-2
docs: update 49_External_database_integration.ipynb
2024-11-23 07:37:40 -05:00
Ikko Eltociear Ashimine 0b584a02c3 docs: update 49_External_database_integration.ipynb
Creat -> Create
2024-11-23 20:08:27 +09:00
davidmezzetti e16d42382b Update Faiss macOS test to force module reload #818 2024-11-22 14:36:15 -05:00
Jeff dceb40c774 Macfaiss (#818)
* macOS platforms faiss OMP Thread patch

* Add TODO

* remove TODO, as build checks for it

* Apply recomendations

* Build Error
2024-11-22 13:38:05 -05:00
davidmezzetti 4f370801e8 Update build script 2024-11-21 22:02:41 -05:00
davidmezzetti 29f680fe89 Add notebook link to documentation 2024-11-21 20:42:19 -05:00
davidmezzetti f0c6c3e0c4 Add example notebook that analyzes the Hugging Face Posts dataset, closes #817 2024-11-21 18:01:47 -05:00
davidmezzetti cdc6eeea6f Fix error with inferring function parameters in agents, closes #816 2024-11-21 14:15:47 -05:00
davidmezzetti 94c05fb231 Update documentation 2024-11-21 14:14:08 -05:00
davidmezzetti 846fbaf377 Update documentation to clarify that passing string prompts to LLM pipeline requires applying chat templates 2024-11-21 14:05:03 -05:00
davidmezzetti cf340e66c3 Update documentation 2024-11-18 22:56:48 -05:00
davidmezzetti b239c7c131 Bump Torch CPU version 2024-11-18 22:56:40 -05:00
davidmezzetti 9444fcc720 Update notebook 2024-11-18 15:50:23 -05:00
davidmezzetti 439b9d7f0c Bump version 2024-11-18 15:50:07 -05:00
davidmezzetti 087de0c2e7 Update notebook 2024-11-18 14:13:37 -05:00
davidmezzetti 5f933e5abd Add agents example notebook, closes #811 2024-11-18 13:28:45 -05:00
davidmezzetti eb573e0366 Add documentation for txtai agents, closes #809 2024-11-18 08:29:25 -05:00
davidmezzetti f582bdf427 Update test 2024-11-15 21:32:27 -05:00
davidmezzetti 731ecd2348 Add agent support to Applications and API #804 2024-11-15 21:31:15 -05:00
davidmezzetti 11bf39ece4 Bump minimum transformers version #807 2024-11-12 10:45:22 -05:00
davidmezzetti 523df52351 Update image 2024-11-09 05:51:56 -05:00
davidmezzetti fbd38ef833 Update documentation for agents #804 2024-11-08 13:57:17 -05:00
davidmezzetti 058ca9bae4 Update tests 2024-11-05 09:02:44 -05:00
davidmezzetti 9ddfc41306 Update return value #804 2024-11-05 07:32:16 -05:00
davidmezzetti 6a71db5f49 Initial version of agents framework #804 2024-11-05 07:17:16 -05:00
davidmezzetti 9739126a99 Update build script #805 2024-11-01 11:14:29 -04:00
davidmezzetti 077ea4182e Update documentation 2024-11-01 10:16:53 -04:00
davidmezzetti 73ae8c3428 Update documentation 2024-11-01 09:14:38 -04:00
davidmezzetti 285769c971 Update build script #805 2024-10-29 13:25:58 -04:00
davidmezzetti 1d5323516e Update build script #805 2024-10-29 12:54:27 -04:00
davidmezzetti ad3e9be663 Update build script #805 2024-10-29 12:12:19 -04:00
davidmezzetti 6b926ccfb1 Update build script #805 2024-10-29 11:35:50 -04:00
davidmezzetti fef13233cf Update build script #805 2024-10-29 11:08:52 -04:00
davidmezzetti 3c15037386 Split pipeline unit tests into packages #805 2024-10-29 09:11:31 -04:00
davidmezzetti aa531e0bff Bump version 2024-10-29 06:52:17 -04:00
davidmezzetti a246052f4a Add model2vec vectorization, closes #801 2024-10-21 13:53:11 -04:00
davidmezzetti 4a268041b7 Update translation pipeline to use hf_hub_download for language detection, closes #803 2024-10-19 06:02:43 -04:00
davidmezzetti 7289f2f25b Pin build script to huggingface-hub==0.25.2 #803 2024-10-18 15:24:23 -04:00
davidmezzetti 79675f5228 Cleanup vectors package, closes #802 2024-10-18 13:39:27 -04:00
davidmezzetti 1ca51e523c Update BASE_IMAGE in Dockerfile, closes #799 2024-10-16 15:33:44 -04:00
davidmezzetti 2635ac587c Pin build script to pillow==10.4.0 #800 2024-10-16 13:55:08 -04:00
davidmezzetti 6f57fb9a1d Update documentation 2024-10-16 09:11:05 -04:00
davidmezzetti 93f707187c Bump version 2024-10-14 14:53:57 -04:00
davidmezzetti 72c68c9a62 Update notebook 2024-10-13 07:54:25 -04:00
davidmezzetti f0a3935ec0 Update documentation 2024-10-13 07:11:37 -04:00
davidmezzetti 1624c5bcb5 Add Generative Audio example notebook, closes #798 2024-10-13 06:28:04 -04:00
davidmezzetti ea4c48b94f Update audio pipelines to improve single item handlers 2024-10-13 06:27:47 -04:00
davidmezzetti c3b3fc9915 Upgrade pylint and black, closes #797 2024-10-11 13:22:11 -04:00
davidmezzetti bbddcd2a4f Require Python 3.9+, closes #796 2024-10-11 12:59:43 -04:00
davidmezzetti 07fa511211 Update documentation 2024-10-11 10:33:00 -04:00
davidmezzetti 1cdc426dce Add dtype to np.array call #793 2024-10-11 10:32:37 -04:00
davidmezzetti 8ffaccfe7a Add Text to Audio pipeline, closes #792. Add support for SpeechT5, closes #793. Updated cache methods, closes #794. Add audio signal processing, closes #795. 2024-10-11 08:30:20 -04:00
davidmezzetti ad2d288d66 Update Text to Speech Generation Notebook, closes #790 2024-09-29 09:03:32 -04:00
davidmezzetti 67321b0b44 Add Speech to Speech example notebook, closes #789 2024-09-27 11:47:23 -04:00
davidmezzetti f3138c2710 Add debug logging 2024-09-27 11:41:25 -04:00
davidmezzetti d9c732dbb6 Update documentation 2024-09-26 21:06:39 -04:00
davidmezzetti cf102730f9 Update build scripts 2024-09-26 20:39:21 -04:00
davidmezzetti ea730ff5ec Refactor microphone pipeline to remove unnecessary dependencies and improve overall logic #785 2024-09-26 20:28:10 -04:00
davidmezzetti 05fe040e68 Update TextToSpeech pipeline to support speaker parameter, closes #787 2024-09-24 08:21:30 -04:00
davidmezzetti c5eed15fe2 Update AudioStream pipeline 2024-09-20 22:22:33 -04:00
davidmezzetti 4f55ffbc11 Update documentation 2024-09-20 15:20:11 -04:00
davidmezzetti 748998d21d Add an audio playback pipeline, closes #786 2024-09-20 13:31:08 -04:00
davidmezzetti 374197b453 Add a microphone pipeline, closes #785 2024-09-20 13:30:32 -04:00
davidmezzetti fffcdadf51 Add streaming speech generation, closes #784 2024-09-20 13:22:41 -04:00
davidmezzetti 65b73eb5e6 Add support for generation keyword arguments with Transcription pipeline, closes #593 2024-09-20 12:23:40 -04:00
davidmezzetti cec5d4f753 Add debug logging for LLM calls 2024-09-20 12:21:28 -04:00
davidmezzetti 7cfe2e7bb4 Test build deps 2024-09-20 08:00:42 -04:00
davidmezzetti b0fdceab9c Test build deps 2024-09-20 07:38:18 -04:00
davidmezzetti 05e8fa973d Update LLM documentation 2024-09-18 18:33:47 -04:00
davidmezzetti 27ed2ce6f7 Documentation update 2024-09-10 09:10:08 -04:00
davidmezzetti dfa2bdce1c Add example notebook covering open data access, closes #782 2024-09-06 11:56:10 -04:00
davidmezzetti d4030edf58 Bump Torch CPU version 2024-09-05 21:10:42 -04:00
davidmezzetti 07aa23820b Bump version 2024-09-05 21:09:54 -04:00
459 changed files with 46095 additions and 6370 deletions
+28 -20
View File
@@ -10,59 +10,67 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
timeout-minutes: 60
timeout-minutes: 75
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v6
- name: Install Python - Linux
uses: actions/setup-python@v4
- name: Install Python
uses: actions/setup-python@v6
with:
python-version: 3.8
if: matrix.os == 'ubuntu-latest'
- name: Install Python - macOS/Windows
uses: actions/setup-python@v4
with:
python-version: 3.9
if: matrix.os != 'ubuntu-latest'
python-version: "3.11"
- name: Install Java
uses: actions/setup-java@v3
uses: actions/setup-java@v5
with:
distribution: "zulu"
java-version: "8"
java-version: 21
- name: Install dependencies - Linux
run: sudo apt-get update && sudo apt-get install libsndfile1
run: |
sudo apt-get update
sudo apt-get install libportaudio2 libsndfile1 libegl1 libgles2
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
if: matrix.os == 'ubuntu-latest'
- name: Install dependencies - macOS
run: |
echo "OMP_NUM_THREADS=1" >> $GITHUB_ENV
echo "PYTORCH_MPS_DISABLE=1" >> $GITHUB_ENV
echo "LLAMA_NO_METAL=1" >> $GITHUB_ENV
echo "TIKA_STARTUP_SLEEP=30" >> $GITHUB_ENV
echo "TIKA_STARTUP_MAX_RETRY=10" >> $GITHUB_ENV
brew install portaudio
pip install torch==2.12.1 torchvision==0.27.1
if: matrix.os == 'macos-latest'
- name: Install dependencies - Windows
run: choco install wget
run: |
"PYTHONIOENCODING=utf-8" >> $env:GITHUB_ENV
choco install wget
if: matrix.os == 'windows-latest'
- name: Build
run: |
pip install -U wheel
pip install .[all,dev] fasttext==0.9.2 faiss-cpu==1.8.0 "numpy < 2.0.0"
pip install .[all,dev]
pip cache purge
python -c "import nltk; nltk.download(['punkt', 'punkt_tab', 'averaged_perceptron_tagger_eng'])"
python --version
make data coverage
env:
HF_HUB_ETAG_TIMEOUT: 100
HF_HUB_DOWNLOAD_TIMEOUT: 100
HF_XET_CHUNK_CACHE_SIZE_BYTES: 0
DOCLING_DEVICE: "cpu"
DOCLING_INFERENCE_COMPILE_TORCH_MODELS: false
- uses: pre-commit/[email protected].0
- uses: pre-commit/[email protected].1
if: matrix.os == 'ubuntu-latest'
- name: Test Coverage
run: coveralls --service=github
run: |
coverage report --fail-under=100
coveralls --service=github
if: matrix.os == 'ubuntu-latest'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+12 -5
View File
@@ -7,12 +7,19 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Checkout code
uses: actions/checkout@v6
- name: Install Python
uses: actions/setup-python@v6
with:
python-version: 3.8
- run: |
python-version: "3.11"
- name: Install txtai
run: |
pip install -U pip wheel
pip install .[all,dev]
- run: mkdocs gh-deploy --force
- name: Deploy documentation
run: mkdocs gh-deploy --force
+22
View File
@@ -0,0 +1,22 @@
# GitHub Actions minimal build
name: minimal
on: ["push", "pull_request"]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Minimal install
run: |
pip install -U pip wheel
MINIMAL=1 pip install .
python -c "import txtai"
+3 -2
View File
@@ -1,13 +1,14 @@
repos:
- repo: https://github.com/pycqa/pylint
rev: v2.16.2
rev: v3.3.1
hooks:
- id: pylint
args:
- -d import-error
- -d duplicate-code
- -d too-many-positional-arguments
- repo: https://github.com/ambv/black
rev: 23.1.0
rev: 24.10.0
hooks:
- id: black
language_version: python3
+2
View File
@@ -12,6 +12,8 @@ max-locals=40
max-returns=10
max-attributes=20
min-public-methods=0
max-public-methods=80
[FORMAT]
max-line-length=150
max-module-lines=1500
+2 -2
View File
@@ -1,8 +1,8 @@
cff-version: 1.2.0
date-released: 2020-08-11
message: "If you use this software, please cite it as below."
title: "txtai: the all-in-one embeddings database"
abstract: "txtai is an all-in-one open-source embeddings database for semantic search, LLM orchestration and language model workflows"
title: "txtai: the all-in-one AI framework"
abstract: "txtai is an all-in-one open-source AI framework for semantic search, LLM orchestration and language model workflows"
url: "https://github.com/neuml/txtai"
authors:
- family-names: "Mezzetti"
+9 -3
View File
@@ -32,9 +32,9 @@ test:
# Run tests while calculating code coverage
coverage:
coverage run -m unittest discover -v -k testagent -s ${TEST_DIR}
coverage run -m unittest discover -v -k testann -s ${TEST_DIR}
coverage run -m unittest discover -v -k testapi.testauthorization -k testapi.testcluster -s ${TEST_DIR}
coverage run -m unittest discover -v -k testapi.testencoding -k testapi.testextension -s ${TEST_DIR}
coverage run -m unittest discover -v -k testapi -s ${TEST_DIR}
coverage run -m unittest discover -v -k testapp -s ${TEST_DIR}
coverage run -m unittest discover -v -k testarchive -s ${TEST_DIR}
coverage run -m unittest discover -v -k testcloud -s ${TEST_DIR}
@@ -42,9 +42,15 @@ coverage:
coverage run -m unittest discover -v -k testdatabase -s ${TEST_DIR}
coverage run -m unittest discover -v -k testembeddings -s ${TEST_DIR}
coverage run -m unittest discover -v -k testgraph -s ${TEST_DIR}
coverage run -m unittest discover -v -k testlibrary -s ${TEST_DIR}
coverage run -m unittest discover -v -k testmodels -s ${TEST_DIR}
coverage run -m unittest discover -v -k testoptional -s ${TEST_DIR}
coverage run -m unittest discover -v -k testpipeline -s ${TEST_DIR}
coverage run -m unittest discover -v -k testpipeline.testaudio -s ${TEST_DIR}
coverage run -m unittest discover -v -k testpipeline.testdata -s ${TEST_DIR}
coverage run -m unittest discover -v -k testpipeline.testimage -s ${TEST_DIR}
coverage run -m unittest discover -v -k testpipeline.testllm -s ${TEST_DIR}
coverage run -m unittest discover -v -k testpipeline.testtext -s ${TEST_DIR}
coverage run -m unittest discover -v -k testpipeline.testtrain -s ${TEST_DIR}
coverage run -m unittest discover -v -k testscoring -s ${TEST_DIR}
coverage run -m unittest discover -v -k testserialize -s ${TEST_DIR}
coverage run -m unittest discover -v -k testvectors -s ${TEST_DIR}
+56 -32
View File
@@ -3,7 +3,7 @@
</p>
<p align="center">
<b>All-in-one embeddings database</b>
<b>All-in-one AI framework</b>
</p>
<p align="center">
@@ -16,7 +16,7 @@
<a href="https://github.com/neuml/txtai/issues">
<img src="https://img.shields.io/github/issues/neuml/txtai.svg?style=flat&color=success" alt="GitHub issues"/>
</a>
<a href="https://join.slack.com/t/txtai/shared_invite/zt-1cagya4yf-DQeuZbd~aMwH5pckBU4vPg">
<a href="https://join.slack.com/t/txtai/shared_invite/zt-37c1zfijp-Y57wMty6YOx_hyIHEQvQJA">
<img src="https://img.shields.io/badge/slack-join-blue?style=flat&logo=slack&logocolor=white" alt="Join Slack"/>
</a>
<a href="https://github.com/neuml/txtai/actions?query=workflow%3Abuild">
@@ -27,14 +27,16 @@
</a>
</p>
txtai is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.
txtai is an all-in-one AI framework for semantic search, LLM orchestration and language model workflows.
![architecture](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/architecture.png#gh-light-mode-only)
![architecture](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/architecture-dark.png#gh-dark-mode-only)
Embeddings databases are a union of vector indexes (sparse and dense), graph networks and relational databases. This enables vector search with SQL, topic modeling, retrieval augmented generation (RAG) and more.
The key component of txtai is an embeddings database, which is a union of vector indexes (sparse and dense), graph networks and relational databases.
Embeddings databases can stand on their own and/or serve as a powerful knowledge source for large language model (LLM) prompts.
This foundation enables vector search and/or serves as a powerful knowledge source for large language model (LLM) applications.
Build autonomous agents, retrieval augmented generation (RAG) processes, multi-model workflows and more.
Summary of txtai features:
@@ -42,12 +44,18 @@ Summary of txtai features:
- 📄 Create embeddings for text, documents, audio, images and video
- 💡 Pipelines powered by language models that run LLM prompts, question-answering, labeling, transcription, translation, summarization and more
- ↪️️ Workflows to join pipelines together and aggregate business logic. txtai processes can be simple microservices or multi-model workflows.
- ⚙️ Build with Python or YAML. API bindings available for [JavaScript](https://github.com/neuml/txtai.js), [Java](https://github.com/neuml/txtai.java), [Rust](https://github.com/neuml/txtai.rs) and [Go](https://github.com/neuml/txtai.go).
- 🤖 Agents that intelligently connect embeddings, pipelines, workflows and other agents together to autonomously solve complex problems
- ⚙️ Web and Model Context Protocol (MCP) APIs. Bindings available for [JavaScript](https://github.com/neuml/txtai.js), [Java](https://github.com/neuml/txtai.java), [Rust](https://github.com/neuml/txtai.rs) and [Go](https://github.com/neuml/txtai.go).
- 🔋 Batteries included with defaults to get up and running fast
- ☁️ Run local or scale out with container orchestration
txtai is built with Python 3.8+, [Hugging Face Transformers](https://github.com/huggingface/transformers), [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [FastAPI](https://github.com/tiangolo/fastapi). txtai is open-source under an Apache 2.0 license.
txtai is built with Python 3.11+, [Hugging Face Transformers](https://github.com/huggingface/transformers), [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [FastAPI](https://github.com/tiangolo/fastapi). txtai is open-source under an Apache 2.0 license.
*Interested in an easy and secure way to run hosted txtai applications? Then join the [txtai.cloud](https://txtai.cloud) preview to learn more.*
> [!NOTE]
>
> [NeuML](https://neuml.com) is the company behind txtai and we provide AI consulting services around our stack. [Schedule a meeting](https://cal.com/neuml/intro) or [send a message](mailto:[email protected]) to learn more.
>
> We're also building an easy and secure way to run hosted txtai applications with [txtai.cloud](https://txtai.cloud).
## Why txtai?
@@ -83,7 +91,7 @@ curl -X GET "http://localhost:8000/search?query=positive"
## Use Cases
The following sections introduce common txtai use cases. A comprehensive set of over 50 [example notebooks and applications](https://neuml.github.io/txtai/examples) are also available.
The following sections introduce common txtai use cases. A comprehensive set of over 70 [example notebooks and applications](https://neuml.github.io/txtai/examples) are also available.
### Semantic Search
@@ -107,11 +115,7 @@ Get started with the following examples.
### LLM Orchestration
LLM chains, retrieval augmented generation (RAG), chat with your data, pipelines and workflows that interface with large language models (LLMs).
#### Chains
Integrate LLM chains (known as workflows in txtai), multiple LLM agents and self-critique.
Autonomous agents, retrieval augmented generation (RAG), chat with your data, pipelines and workflows that interface with large language models (LLMs).
![llm](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/llm.png)
@@ -122,6 +126,24 @@ See below to learn more.
| [Prompt templates and task chains](https://github.com/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) | Build model prompts and connect tasks together with workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) |
| [Integrate LLM frameworks](https://github.com/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) | Integrate llama.cpp, LiteLLM and custom generation frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) |
| [Build knowledge graphs with LLMs](https://github.com/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) | Build knowledge graphs with LLM-driven entity extraction | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) |
| [Parsing the stars with txtai](https://github.com/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) | Explore an astronomical knowledge graph of known stars, planets, galaxies | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) |
#### Agents
Agents connect embeddings, pipelines, workflows and other agents together to autonomously solve complex problems.
![agent](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/agent.png)
txtai agents are built on top of the [smolagents](https://github.com/huggingface/smolagents) framework. This supports all LLMs txtai supports (Hugging Face, llama.cpp, OpenAI / Claude / AWS Bedrock via LiteLLM). Agent prompting with [`agents.md`](https://github.com/agentsmd/agents.md) and [`skill.md`](https://agentskills.io/specification) are also supported.
Check out this [Agent Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/agent_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Granting autonomy to agents](https://github.com/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) | Agents that iteratively solve problems as they see fit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) |
| [TxtAI got skills](https://github.com/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) | Integrate skill.md files with your agent | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) |
| [Agent Tools](https://github.com/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) [▶️](https://www.youtube.com/watch?v=RDNaFXQy3GQ) | Learn about the txtai agent toolkit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) |
| [Analyzing LinkedIn Company Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) | Exploring how to improve social media engagement with AI | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) |
#### Retrieval augmented generation
@@ -130,14 +152,14 @@ Retrieval augmented generation (RAG) reduces the risk of LLM hallucinations by c
![rag](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/rag.png#gh-light-mode-only)
![rag](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/rag-dark.png#gh-dark-mode-only)
A novel feature of txtai is that it can provide both an answer and source citation.
Check out this [RAG Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/rag_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [How RAG with txtai works](https://github.com/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) | Create RAG processes, API services and Docker instances | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) |
| [Advanced RAG with graph path traversal](https://github.com/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) | Graph path traversal to collect complex sets of data for advanced RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) |
| [Advanced RAG with guided generation](https://github.com/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) | Retrieval Augmented and Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) [▶️](https://www.youtube.com/watch?v=t_OeAc8NVfQ) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [RAG is more than Vector Search](https://github.com/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) | Context retrieval via Web, SQL and other sources | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) |
| [GraphRAG with Wikipedia and GPT OSS](https://github.com/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) | Deep graph search powered RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) |
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
### Language Model Workflows
@@ -148,6 +170,8 @@ Language model workflows, also known as semantic workflows, connect language mod
While LLMs are powerful, there are plenty of smaller, more specialized models that work better and faster for specific tasks. This includes models for extractive question-answering, automatic summarization, text-to-speech, transcription and translation.
Check out this [Workflow Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/workflow_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Run pipeline workflows](https://github.com/neuml/txtai/blob/master/examples/14_Run_pipeline_workflows.ipynb) [▶️](https://www.youtube.com/watch?v=UBMPDCn1gEU) | Simple yet powerful constructs to efficiently process data | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/14_Run_pipeline_workflows.ipynb) |
@@ -166,9 +190,9 @@ The easiest way to install is via pip and PyPI
pip install txtai
```
Python 3.8+ is supported. Using a Python [virtual environment](https://docs.python.org/3/library/venv.html) is recommended.
Python 3.11+ is supported. Using a Python [virtual environment](https://docs.python.org/3/library/venv.html) is recommended.
See the detailed [install instructions](https://neuml.github.io/txtai/install) for more information covering [optional dependencies](https://neuml.github.io/txtai/install/#optional-dependencies), [environment specific prerequisites](https://neuml.github.io/txtai/install/#environment-specific-prerequisites), [installing from source](https://neuml.github.io/txtai/install/#install-from-source), [conda support](https://neuml.github.io/txtai/install/#conda) and how to [run with containers](https://neuml.github.io/txtai/cloud).
See the detailed [install instructions](https://neuml.github.io/txtai/install) for more information covering [optional dependencies](https://neuml.github.io/txtai/install/#optional-dependencies), [environment specific prerequisites](https://neuml.github.io/txtai/install/#environment-specific-prerequisites), [installing from source](https://neuml.github.io/txtai/install/#install-from-source), [conda support](https://neuml.github.io/txtai/install/#conda), [lightweight minimal installation](https://neuml.github.io/txtai/install/#minimal-install) and how to [run with containers](https://neuml.github.io/txtai/cloud).
## Model guide
@@ -180,9 +204,9 @@ See the table below for the current recommended models. These models all allow c
| ----------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [Embeddings](https://neuml.github.io/txtai/embeddings) | [all-MiniLM-L6-v2](https://hf.co/sentence-transformers/all-MiniLM-L6-v2) |
| [Image Captions](https://neuml.github.io/txtai/pipeline/image/caption) | [BLIP](https://hf.co/Salesforce/blip-image-captioning-base) |
| [Labels - Zero Shot](https://neuml.github.io/txtai/pipeline/text/labels) | [BART-Large-MNLI](https://hf.co/facebook/bart-large) |
| [Labels - Zero Shot](https://neuml.github.io/txtai/pipeline/text/labels) | [DeBERTa v3 Zeroshot](https://hf.co/MoritzLaurer/deberta-v3-base-zeroshot-v2.0-c) |
| [Labels - Fixed](https://neuml.github.io/txtai/pipeline/text/labels) | Fine-tune with [training pipeline](https://neuml.github.io/txtai/pipeline/train/trainer) |
| [Large Language Model (LLM)](https://neuml.github.io/txtai/pipeline/text/llm) | [Mistral 7B OpenOrca](https://hf.co/Open-Orca/Mistral-7B-OpenOrca) |
| [Large Language Model (LLM)](https://neuml.github.io/txtai/pipeline/text/llm) | [Gemma 4 31B](https://hf.co/google/gemma-4-31B) |
| [Summarization](https://neuml.github.io/txtai/pipeline/text/summary) | [DistilBART](https://hf.co/sshleifer/distilbart-cnn-12-6) |
| [Text-to-Speech](https://neuml.github.io/txtai/pipeline/audio/texttospeech) | [ESPnet JETS](https://hf.co/NeuML/ljspeech-jets-onnx) |
| [Transcription](https://neuml.github.io/txtai/pipeline/audio/transcription) | [Whisper](https://hf.co/openai/whisper-base) |
@@ -194,9 +218,8 @@ See the following links to learn more.
- [Hugging Face Tasks](https://hf.co/tasks)
- [Hugging Face Model Hub](https://hf.co/models)
- [MTEB Leaderboard](https://hf.co/spaces/mteb/leaderboard)
- [LMSYS LLM Leaderboard](https://chat.lmsys.org/?leaderboard)
- [Open LLM Leaderboard](https://hf.co/spaces/HuggingFaceH4/open_llm_leaderboard)
- [Embeddings Leaderboard](https://hf.co/spaces/mteb/leaderboard)
- [LLM Leaderboard](https://hf.co/spaces/lmarena-ai/arena-leaderboard)
## Powered by txtai
@@ -206,10 +229,10 @@ The following applications are powered by txtai.
| Application | Description |
|:------------ |:-------------|
| [txtchat](https://github.com/neuml/txtchat) | Retrieval Augmented Generation (RAG) powered search |
| [paperai](https://github.com/neuml/paperai) | Semantic search and workflows for medical/scientific papers |
| [codequestion](https://github.com/neuml/codequestion) | Semantic search for developers |
| [tldrstory](https://github.com/neuml/tldrstory) | Semantic search for headlines and story text |
| [rag](https://github.com/neuml/rag) | Retrieval Augmented Generation (RAG) application |
| [ncoder](https://github.com/neuml/ncoder) | Open-Source AI coding agent |
| [paperai](https://github.com/neuml/paperai) | AI for medical and scientific papers |
| [annotateai](https://github.com/neuml/annotateai) | Automatically annotate papers with LLMs |
In addition to this list, there are also many other [open-source projects](https://github.com/neuml/txtai/network/dependents), [published research](https://scholar.google.com/scholar?q=txtai&hl=en&as_ylo=2022) and closed proprietary/commercial projects that have built on txtai in production.
@@ -218,9 +241,10 @@ In addition to this list, there are also many other [open-source projects](https
![further](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/further.png#gh-light-mode-only)
![further](https://raw.githubusercontent.com/neuml/txtai/master/docs/images/further-ghdark.png#gh-dark-mode-only)
- [Introducing txtai, the all-in-one embeddings database](https://medium.com/neuml/introducing-txtai-the-all-in-one-embeddings-database-c721f4ff91ad)
- [Introducing txtai, the all-in-one AI framework](https://medium.com/neuml/introducing-txtai-the-all-in-one-ai-framework-0660ecfc39d7)
- [txtai: An All-in-One AI Framework for Semantic Search and LLM Workflows](https://github.com/neuml/papers/blob/master/txtai/txtai.pdf)
- [Tutorial series on Hashnode](https://neuml.hashnode.dev/series/txtai-tutorial) | [dev.to](https://dev.to/neuml/tutorial-series-on-txtai-ibg)
- [What's new in txtai 7.0](https://medium.com/neuml/whats-new-in-txtai-7-0-855ad6a55440) | [6.0](https://medium.com/neuml/whats-new-in-txtai-6-0-7d93eeedf804) | [5.0](https://medium.com/neuml/whats-new-in-txtai-5-0-e5c75a13b101) | [4.0](https://medium.com/neuml/whats-new-in-txtai-4-0-bbc3a65c3d1c)
- [What's new in txtai 9.0](https://medium.com/neuml/whats-new-in-txtai-9-0-d522bb150afa) | [8.0](https://medium.com/neuml/whats-new-in-txtai-8-0-2d7d0ab4506b) | [7.0](https://medium.com/neuml/whats-new-in-txtai-7-0-855ad6a55440) | [6.0](https://medium.com/neuml/whats-new-in-txtai-6-0-7d93eeedf804) | [5.0](https://medium.com/neuml/whats-new-in-txtai-5-0-e5c75a13b101) | [4.0](https://medium.com/neuml/whats-new-in-txtai-4-0-bbc3a65c3d1c)
- [Getting started with semantic search](https://medium.com/neuml/getting-started-with-semantic-search-a9fd9d8a48cf) | [workflows](https://medium.com/neuml/getting-started-with-semantic-workflows-2fefda6165d9) | [rag](https://medium.com/neuml/getting-started-with-rag-9a0cca75f748)
- [Running txtai at scale](https://medium.com/neuml/running-at-scale-with-txtai-71196cdd99f9)
- [Vector search & RAG Landscape: A review with txtai](https://medium.com/neuml/vector-search-rag-landscape-a-review-with-txtai-a7f37ad0e187)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 KiB

After

Width:  |  Height:  |  Size: 295 KiB

+5 -5
View File
@@ -1,5 +1,5 @@
# Set base image
ARG BASE_IMAGE=ubuntu:20.04
ARG BASE_IMAGE=python:3.11-slim
FROM $BASE_IMAGE
# Install GPU-enabled version of PyTorch if set
@@ -8,7 +8,7 @@ ARG GPU
# Target CPU architecture
ARG TARGETARCH
# Set Python version (i.e. 3, 3.8)
# Set Python version (i.e. 3, 3.11)
ARG PYTHON_VERSION=3
# List of txtai components to install
@@ -21,18 +21,18 @@ ENV LANG=C.UTF-8
RUN \
# Install required packages
apt-get update && \
apt-get -y --no-install-recommends install libgomp1 libsndfile1 gcc g++ python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python3-pip && \
apt-get -y --no-install-recommends install libgomp1 libportaudio2 libsndfile1 libegl1 libgles2 libvulkan1 git gcc g++ python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python3-pip && \
rm -rf /var/lib/apt/lists && \
\
# Install txtai project and dependencies
ln -s /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
python -m pip install --no-cache-dir -U pip wheel setuptools && \
if [ -z ${GPU} ] && { [ -z ${TARGETARCH} ] || [ ${TARGETARCH} = "amd64" ] ;}; then pip install --no-cache-dir torch==2.3.1+cpu torchvision==0.18.1+cpu -f https://download.pytorch.org/whl/torch_stable.html; fi && \
if [ -z ${GPU} ]; then pip install --no-cache-dir torch==2.14.1+cpu torchvision==0.29.1+cpu -f https://download.pytorch.org/whl/torch -f https://download.pytorch.org/whl/torchvision; fi && \
python -m pip install --no-cache-dir txtai${COMPONENTS} && \
python -c "import sys, importlib.util as util; 1 if util.find_spec('nltk') else sys.exit(); import nltk; nltk.download(['punkt', 'punkt_tab', 'averaged_perceptron_tagger_eng'])" && \
\
# Cleanup build packages
apt-get -y purge gcc g++ python${PYTHON_VERSION}-dev && apt-get -y autoremove
apt-get -y purge git gcc g++ python${PYTHON_VERSION}-dev && apt-get -y autoremove
# Set default working directory
WORKDIR /app
+20
View File
@@ -0,0 +1,20 @@
# Set base image
ARG BASE_IMAGE=python:3.11-slim
FROM $BASE_IMAGE
# Target CPU architecture
ARG TARGETARCH
# Set Python version (i.e. 3, 3.11)
ARG PYTHON_VERSION=3
# Locale environment variables
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
RUN \
# Install minimal txtai project and dependencies
MINIMAL=1 python -m pip install --no-cache-dir txtai_minimal
# Set default working directory
WORKDIR /app
+141
View File
@@ -0,0 +1,141 @@
# Configuration
An agent takes two main arguments, an LLM and a list of tools.
The txtai agent framework is built with [smolagents](https://github.com/huggingface/smolagents). Additional options can be passed in the `Agent` constructor.
```python
from datetime import datetime
from txtai import Agent
wikipedia = {
"name": "wikipedia",
"description": "Searches a Wikipedia database",
"provider": "huggingface-hub",
"container": "neuml/txtai-wikipedia"
}
arxiv = {
"name": "arxiv",
"description": "Searches a database of scientific papers",
"provider": "huggingface-hub",
"container": "neuml/txtai-arxiv"
}
def today() -> str:
"""
Gets the current date and time
Returns:
current date and time
"""
return datetime.today().isoformat()
agent = Agent(
model="Qwen/Qwen3-4B-Instruct-2507",
tools=[today, wikipedia, arxiv, "websearch"],
)
```
## model
```yaml
model: string|llm instance
```
LLM model path or LLM pipeline instance. The `llm` parameter is also supported for backwards compatibility.
See the [LLM pipeline](../../pipeline/text/llm) for more information.
## tools
```yaml
tools: list
```
List of tools to supply to the agent. Supports the following configurations.
### function
A function tool takes the following dictionary fields.
| Field | Description |
|:------------|:-------------------------|
| name | name of the tool |
| description | tool description |
| target | target method / callable |
A function or callable method can also be directly supplied in the `tools` list. In this case, the fields are inferred from the method documentation.
### embeddings
Embeddings indexes have built-in support. Provide the following dictionary configuration to add an embeddings index as a tool.
| Field | Description |
|:------------|:-------------------------------------------|
| name | embeddings index name |
| description | embeddings index description |
| **kwargs | Parameters to pass to [embeddings.load](../../embeddings/methods/#txtai.embeddings.Embeddings.load) |
### tool
The following shortcut strings load tools directly. Passing a Tool instance is also supported.
| Tool | Description |
|:------------|:----------------------------------------------------------|
| bash | Runs a shell command through subprocess |
| defaults | Loads all of these tools as the default toolkit |
| edit | Edits a file in place and returns a diff |
| glob | Finds matching file patterns in a directory |
| grep | Finds matching file content in a directory |
| http.* | HTTP Path to a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/docs/getting-started/intro) server |
| python | Runs a Python action |
| read | Reads file or url content, supports text extraction |
| todowrite | Generates a task list to organize complex tasks |
| websearch | Runs a websearch using the built-in websearch tool |
| webview | Extracts content from a web page. Alias for `read` tool |
| write | Writes content to file |
| *.md | Loads a [`skill.md`](https://agentskills.io/specification) file |
## instructions
```yaml
instructions: string|path
```
Supports loading an `agents.md` file. Can be provided directly as a string or as a path to a file.
[Read more about agents.md here](https://github.com/agentsmd/agents.md)
## template
```yaml
template: string
```
Customize the prompt template used by this agent. Supports Jinja templates. Uses a default template when this parameter is not provided.
Must include `{{ text }}` and `{{ memory }}` placeholders.
## memory
```yaml
memory: int
```
Keeps a rolling window of `memory` inputs and outputs. These are added to future prompts and serve as "agent memory".
Supports storing memory by `session` to enable multiple conversation threads. Defaults to shared memory when not set. See the [method documentation](../methods#txtai.agent.base.Agent.__call__) for more information.
## method
```yaml
method: code|tool
```
Sets the agent method. Supports either a `code` or `tool` (default) calling agent. A code agent generates Python code and executes that. A tool calling agent generates JSON blocks and calls the agents within those blocks.
Additional options can be directly passed. See [CodeAgent](https://huggingface.co/docs/smolagents/main/en/reference/agents#smolagents.CodeAgent) or [ToolCallingAgent](https://huggingface.co/docs/smolagents/main/en/reference/agents#smolagents.ToolCallingAgent) for a list of parameters.
[Read more here](https://huggingface.co/docs/smolagents/main/en/guided_tour).
+156
View File
@@ -0,0 +1,156 @@
# Agent
![agent](../images/agent.png)
An agent automatically creates workflows to answer multi-faceted user requests. Agents iteratively prompt and/or interface with tools to
step through a process and ultimately come to an answer for a request.
Agent prompting with [`agents.md`](https://github.com/agentsmd/agents.md) and [`skill.md`](https://agentskills.io/specification) are also supported. [Read the configuration](./configuration/#tool) for more on how to setup those up.
Agents excel at complex tasks where multiple tools and/or methods are required. They incorporate a level of randomness similar to different
people working on the same task. When the request is simple and/or there is a rule-based process, other methods such as RAG and Workflows
should be explored.
The following code snippet defines a basic agent.
```python
from datetime import datetime
from txtai import Agent
wikipedia = {
"name": "wikipedia",
"description": "Searches a Wikipedia database",
"provider": "huggingface-hub",
"container": "neuml/txtai-wikipedia"
}
arxiv = {
"name": "arxiv",
"description": "Searches a database of scientific papers",
"provider": "huggingface-hub",
"container": "neuml/txtai-arxiv"
}
def today() -> str:
"""
Gets the current date and time
Returns:
current date and time
"""
return datetime.today().isoformat()
agent = Agent(
model="Qwen/Qwen3-4B-Instruct-2507",
tools=[today, wikipedia, arxiv, "websearch"],
max_steps=10,
)
```
The agent above has access to two embeddings databases (Wikipedia and ArXiv) and the web. Given the user's input request, the agent decides the best tool to solve the task.
## Example
The first example will solve a problem with multiple data points. See below.
```python
agent("Which city has the highest population, Boston or New York?")
```
This requires looking up the population of each city before knowing how to answer the question. Multiple search requests are run to generate a final answer.
## Agentic RAG
Standard retrieval augmented generation (RAG) runs a single vector search to obtain a context and builds a prompt with the context + input question. Agentic RAG is a more complex process that goes through multiple iterations. It can also utilize multiple databases to come to a final conclusion.
The example below aggregates information from multiple sources and builds a report on a topic.
```python
researcher = """
You're an expert researcher looking to write a paper on {topic}.
Search for websites, scientific papers and Wikipedia related to the topic.
Write a report with summaries and references (with hyperlinks).
Write the text as Markdown.
"""
agent(researcher.format(topic="alien life"))
```
## Agent Teams
Agents can also be tools. This enables the concept of building "Agent Teams" to solve problems. The previous example can be rewritten as a list of agents.
```python
from txtai import Agent, LLM
llm = LLM("Qwen/Qwen3-4B-Instruct-2507")
websearcher = Agent(
model=llm,
tools=["websearch"],
)
wikiman = Agent(
model=llm,
tools=[{
"name": "wikipedia",
"description": "Searches a Wikipedia database",
"provider": "huggingface-hub",
"container": "neuml/txtai-wikipedia"
}],
)
researcher = Agent(
model=llm,
tools=[{
"name": "arxiv",
"description": "Searches a database of scientific papers",
"provider": "huggingface-hub",
"container": "neuml/txtai-arxiv"
}],
)
agent = Agent(
model=llm,
tools=[{
"name": "websearcher",
"description": "I run web searches, there is no answer a web search can't solve!",
"target": websearcher
}, {
"name": "wikiman",
"description": "Wikipedia has all the answers, I search Wikipedia and answer questions",
"target": wikiman
}, {
"name": "researcher",
"description": "I'm a science guy. I search arXiv to get all my answers.",
"target": researcher
}],
max_steps=10
)
```
This provides another level of intelligence to the process. Instead of just a single tool execution, each agent-tool combination has it's own reasoning engine.
```python
agent("""
Research fundamental concepts about Signal Processing and build a comprehensive report.
Write the output in Markdown.
""")
```
# More examples
Check out this [Agent Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/agent_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [What's new in txtai 8.0](https://github.com/neuml/txtai/blob/master/examples/67_Whats_new_in_txtai_8_0.ipynb) | Agents with txtai | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/67_Whats_new_in_txtai_8_0.ipynb) |
| [Analyzing Hugging Face Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) | Explore a rich dataset with Graph Analysis and Agents | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) |
| [Granting autonomy to agents](https://github.com/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) | Agents that iteratively solve problems as they see fit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) |
| [Analyzing LinkedIn Company Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) | Exploring how to improve social media engagement with AI | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) |
| [Parsing the stars with txtai](https://github.com/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) | Explore an astronomical knowledge graph of known stars, planets, galaxies | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) |
| [Agentic College Search](https://github.com/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) | Identify list of strong engineering colleges | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) |
| [TxtAI got skills](https://github.com/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) | Integrate skill.md files with your agent | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) |
| [Agent Tools](https://github.com/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) [▶️](https://www.youtube.com/watch?v=RDNaFXQy3GQ) | Learn about the txtai agent toolkit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) |
+4
View File
@@ -0,0 +1,4 @@
# Methods
## ::: txtai.agent.base.Agent.__init__
## ::: txtai.agent.base.Agent.__call__
+26 -1
View File
@@ -33,11 +33,36 @@ Path to save and load the embeddings index. Each API instance can only access a
writable: boolean
```
Determines if the input embeddings index is writable (true) or read-only (false). This allows serving a read-only index.
Sets this embeddings index as writable (true) or read-only (false). This allows serving a read-only index. Defaults to read-only.
### reindex
```yaml
reindex: boolean
```
Enables re-indexing for this embeddings index (defaults to disabled).
Re-indexing accepts new configuration and should only be enabled when the configuration comes from trusted sources.
### cloud
[Cloud storage settings](../../embeddings/configuration/cloud) can be set under a `cloud` top level configuration group.
## Agent
Agents are defined under a top level `agent` key. Each key under the `agent` key is the name of the agent. Constructor parameters can be passed under this key.
The following example defines an agent.
```yaml
agent:
researcher:
tools:
- websearch
llm:
path: Qwen/Qwen3-4B-Instruct-2507
```
## Pipeline
Pipelines are loaded as top level configuration parameters. Pipeline names are automatically detected in the YAML configuration and created upon startup. All [pipelines](../../pipeline) are supported.
+8 -1
View File
@@ -120,8 +120,15 @@ The following programming languages have bindings with the txtai API:
- [Rust](https://github.com/neuml/txtai.rs)
- [Go](https://github.com/neuml/txtai.go)
See the link below for a detailed example covering how to use the API.
The API also supports hosting [OpenAI-compatible](./openai) and [Model Context Protocol (MCP)](./mcp) endpoints.
See the links below for detailed examples covering the API.
| Notebook | Description | |
|:----------|:-------------|------:|
| [API Gallery](https://github.com/neuml/txtai/blob/master/examples/08_API_Gallery.ipynb) | Using txtai in JavaScript, Java, Rust and Go | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/08_API_Gallery.ipynb) |
| [Distributed embeddings cluster](https://github.com/neuml/txtai/blob/master/examples/15_Distributed_embeddings_cluster.ipynb) | Distribute an embeddings index across multiple data nodes | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/15_Distributed_embeddings_cluster.ipynb) |
| [Embeddings in the Cloud](https://github.com/neuml/txtai/blob/master/examples/43_Embeddings_in_the_Cloud.ipynb) | Load and use an embeddings index from the Hugging Face Hub | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/43_Embeddings_in_the_Cloud.ipynb) |
| [Custom API Endpoints](https://github.com/neuml/txtai/blob/master/examples/51_Custom_API_Endpoints.ipynb) | Extend the API with custom endpoints | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/51_Custom_API_Endpoints.ipynb) |
| [API Authorization and Authentication](https://github.com/neuml/txtai/blob/master/examples/54_API_Authorization_and_Authentication.ipynb) | Add authorization, authentication and middleware dependencies to the API | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/54_API_Authorization_and_Authentication.ipynb) |
| [OpenAI Compatible API](https://github.com/neuml/txtai/blob/master/examples/74_OpenAI_Compatible_API.ipynb) | Connect to txtai with a standard OpenAI client library | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/74_OpenAI_Compatible_API.ipynb) |
+34
View File
@@ -0,0 +1,34 @@
# Model Context Protocol
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that enables developers to build secure, two-way connections between their data sources and AI-powered tools.
The API can be configured to handle MCP requests. All enabled endpoints set in the API configuration are automatically added as MCP tools.
```yaml
mcp: boolean|dict
```
When `mcp` is a boolean, default arguments are used. When `mcp` is a dictionary it supports the following options.
```yaml
mcp:
clientargs: http client options (dict)
mcpargs: FastApiMCP options (dict)
```
See the following links for details on the options.
- [HTTP Client Arguments](https://www.python-httpx.org/api/#asyncclient)
- [FastApiMCP Arguments](https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py#L22)
Once this configuration option is added, a new route is added to the application `/mcp`.
The [Model Context Protocol Inspector tool](https://www.npmjs.com/package/@modelcontextprotocol/inspector) is a quick way to explore how the MCP tools are exported through this interface.
Run the following and go to the local URL specified.
```
npx @modelcontextprotocol/inspector node build/index.js
```
Enter `http://localhost:8000/mcp` to see the full list of tools available.
+13
View File
@@ -0,0 +1,13 @@
# OpenAI-compatible API
The API can be configured to serve an OpenAI-compatible API as shown below.
```yaml
openai: True
```
See the link below for a detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [OpenAI Compatible API](https://github.com/neuml/txtai/blob/master/examples/74_OpenAI_Compatible_API.ipynb) | Connect to txtai with a standard OpenAI client library | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/74_OpenAI_Compatible_API.ipynb) |
+43 -2
View File
@@ -6,9 +6,9 @@ The default implementation of an API service runs via HTTP and is fully open. If
The default API service command starts a Uvicorn server as a HTTP service on port 8000. To run a HTTPS service, consider the following options.
- [TLS Proxy Server](https://fastapi.tiangolo.com/deployment/https/). *Recommended choice*. With this configuration, the txtai API service runs as a HTTP service only accessible on the localhost/local network. The proxy server handles all encryption and redirects requests to local services. See this [example configuration](https://www.uvicorn.org/deployment/#running-behind-nginx) for more.
- [TLS Proxy Server](https://fastapi.tiangolo.com/deployment/https/). *Recommended choice*. With this configuration, the txtai API service runs as a HTTP service only accessible on the localhost/local network. The proxy server handles all encryption and redirects requests to local services. See this [example configuration](https://www.uvicorn.dev/deployment/#running-behind-nginx) for more.
- [Uvicorn SSL Certificate](https://www.uvicorn.org/deployment/). Another option is setting the SSL certificate on the Uvicorn service. This works in simple situations but gets complex when hosting multiple txtai or other related services.
- [Uvicorn SSL Certificate](https://www.uvicorn.dev/deployment/). Another option is setting the SSL certificate on the Uvicorn service. This works in simple situations but gets complex when hosting multiple txtai or other related services.
## Authorization
@@ -31,3 +31,44 @@ curl \
It's important to note that HTTPS **must** be enabled using one of the methods mentioned above. Otherwise, tokens will be exchanged as clear text.
Authentication and Authorization can be fully customized. See the [dependencies](../customization#dependencies) section for more.
## Safe Open
Many components in txtai work with local files and have no restrictions on what files and urls can be accessed. The [textractor pipeline](../../pipeline/data/textractor) and [retrieve](../../workflow/task/retrieve) tasks both have a built-in option called `safeopen` which is enabled by default when running the API and applications. It enforces the following rules:
- Local files must be in the safeopen directory (defaults to temp dir)
- URLs must be public URLs (also has checks for redirects and DNS rebind attempts)
The following workflow only allows accessing files stored in a specific directory along with public urls.
```yaml
workflow:
textract:
tasks:
- action: textractor
```
A number of of pipelines support reading local files. For these it's recommended to wrap those pipelines as workflows with a `retrieve` task. Note that pipelines can be created in-line and don't need to be exposed via the API.
```yaml
workflow:
caption:
tasks:
- task: retrieve
action: caption
```
Additionally, internal pipelines can be created but not exposed via the API.
```yaml
routes:
caption: False
caption:
workflow:
caption:
tasks:
- task: retrieve
action: caption
```
+3 -3
View File
@@ -8,7 +8,7 @@ Scalable cloud-native applications can be built with txtai. The following cloud
- Container Orchestration Systems (i.e. Kubernetes)
- Docker Engine
- Serverless Compute
- txtai.cloud (coming in 2024)
- txtai.cloud (planned for future)
Images for txtai are available on Docker Hub for [CPU](https://hub.docker.com/r/neuml/txtai-cpu) and [GPU](https://hub.docker.com/r/neuml/txtai-gpu) installs. The CPU install is recommended when GPUs aren't available given the image is significantly smaller.
@@ -30,8 +30,8 @@ Examples build commands below.
# Get Dockerfile
wget https://raw.githubusercontent.com/neuml/txtai/master/docker/base/Dockerfile
# Build Ubuntu 20.04 image running Python 3.8
docker build -t txtai --build-arg BASE_IMAGE=ubuntu:20.04 --build-arg PYTHON_VERSION=3.8 .
# Build Ubuntu 22.04 image running Python 3.11
docker build -t txtai --build-arg BASE_IMAGE=ubuntu:22.04 --build-arg PYTHON_VERSION=3.11 .
# Build image with GPU support
docker build -t txtai --build-arg GPU=1 .
+86 -3
View File
@@ -4,7 +4,7 @@ Approximate Nearest Neighbor (ANN) index configuration for storing vector embedd
## backend
```yaml
backend: faiss|hnsw|annoy|numpy|torch|pgvector|sqlite|custom
backend: faiss|hnsw|annoy|ggml|milvus|numpy|rabitq|torch|turbovec|zvec|pgvector|sqlite|custom
```
Sets the ANN backend. Defaults to `faiss`. Additional backends are available via the [ann](../../../install/#ann) extras package. Set custom backends via setting this parameter to the fully resolvable class string.
@@ -40,6 +40,8 @@ See the following Faiss documentation links for more information.
- [Binary Indexes](https://github.com/facebookresearch/faiss/wiki/Binary-indexes)
- [Search Tuning](https://github.com/facebookresearch/faiss/wiki/Faster-search)
Note: For macOS users, an existing bug in an upstream package restricts the number of processing threads to 1. This limitation is managed internally to prevent system crashes.
### hnsw
```yaml
hnsw:
@@ -60,18 +62,99 @@ annoy:
See [Annoy documentation](https://github.com/spotify/annoy#full-python-api) for more information on these parameters. Note that annoy indexes can not be modified after creation, upserts/deletes and other modifications are not supported.
### ggml
```yaml
ggml:
gpu: enable GPU - defaults to True
quantize: sets the tensor quantization - defaults to F32
querysize: query buffer size - defaults to 64
```
The [GGML](https://github.com/ggml-org/ggml) backend is a k-nearest neighbors backend. It stores tensors using GGML and [GGUF](https://huggingface.co/docs/hub/en/gguf). It supports GPU-enabled operations and supports quantization. GGML is the framework used by [llama.cpp](https://github.com/ggml-org/llama.cpp).
[See this](https://github.com/ggml-org/ggml/blob/master/include/ggml.h#L379) for a list of quantization types.
### milvus
```yaml
milvus:
m: number of HNSW links per element (int) - defaults to 50
```
### numpy
The NumPy backend is a k-nearest neighbors backend. It's designed for simplicity and works well with smaller datasets.
```yaml
numpy:
safetensors: stores vectors using the safetensors format
defaults to NumPy array storage
```
The `torch` backend supports the same options. The only difference is that the vectors can be search using GPUs.
The NumPy backend is a k-nearest neighbors backend. It's designed for simplicity and works well with smaller datasets that fit into memory.
### rabitq
```yaml
rabitq:
mode: index mode (ivf or hnsw) - defaults to "ivf"
nbits: number of quantization bits per dimension (int) - defaults to 1,
supports 1 to 9 in both modes, ivf mode also supports 32 which
keeps raw vectors for reranking
clusters: number of IVF clusters (int) - defaults to
max(1, min(round(4 * sqrt(embeddings count)), embeddings count))
nprobe: search probe setting for ivf mode (int) - defaults to
max(1, round(num_clusters/16))
m: M param for hnsw mode (int) - defaults to 16
efconstruction: ef_construction param for hnsw mode (int) - defaults to 200
efsearch: ef search param for hnsw mode (int) - defaults to None and not set
randomseed: random-seed param for hnsw mode (int) - defaults to 100
```
The [rabitq](https://github.com/VectorDB-NTU/RaBitQ-Library) backend is a quantized index powered by the [RaBitQ algorithm](https://doi.org/10.1145/3725413). It supports ivf and hnsw search modes. Vectors are stored with 1-bit quantization by default. More bits increase accuracy at the cost of memory. The index is stored as a single file and no vectors are kept outside of it. With nbits set to 32, the vectors are stored in the index for reranking. The ivf mode supports upserts and deletes. Deleted rows keep their storage. Rows added after the first index are assigned to the clusters trained when the index was built, so recall can drop if the new data differs from the original data. Rebuild the index to train new clusters. Note that hnsw indexes can not be modified after creation, upserts/deletes and other modifications are not supported.
### torch
```yaml
torch:
safetensors: stores vectors using the safetensors format - defaults
to NumPy array storage if quantization is disabled
quantize:
type: quantization type (fp4, nf4, int8)
blocksize: quantization block size parameter
```
The Torch backend is a k-nearest neighbors backend like NumPy. It supports GPU-enabled operations. It also has support for quantization which enables fitting larger arrays into GPU memory.
When quantization is enabled, vectors are _always_ stored in safetensors. _Note that macOS support for quantization is limited._
### turbovec
```yaml
turbovec:
bitwidth: number of bits to store each vector dimension as. Supports 2, 3 or 4.
```
The [turbovec](https://github.com/RyanCodrai/turbovec) backend is a k-nearest neighbors backend powered by the [TurboQuant algorithm](https://arxiv.org/abs/2504.19874).
### zvec
```yaml
zvec:
efconstruction: ef_construction param for HnswIndexParam (int) - defaults to 200
m: number of HNSW links per element (int) - defaults to 50
efsearch: ef search param for HnswQueryParam (int) - defaults to 300
```
The [zvec](https://github.com/alibaba/zvec) backend is an embedded, path-based vector index.
### pgvector
```yaml
pgvector:
url: database url connection string, alternatively can be set via
ANN_URL environment variable
schema: database schema to store vectors - defaults to being
determined by the database
table: database table to store vectors - defaults to `vectors`
precision: vector float precision (half or full) - defaults to `full`
efconstruction: ef_construction param (int) - defaults to 200
m: M param for init_index (int) - defaults to 16
```
+13 -1
View File
@@ -11,7 +11,7 @@ provider: string
Cloud provider. Can be one of the following:
- Cloud object storage. Set to one of these [providers](https://libcloud.readthedocs.io/en/stable/storage/supported_providers.html).
- Cloud object storage. Set to one of these [providers](https://libcloud.readthedocs.io/en/stable/storage/supported_providers.html). Use the text shown in the `Provider Constant` column as lower case.
- Hugging Face Hub. Set to `huggingface-hub`.
@@ -44,6 +44,18 @@ secret: string
Provider-specific access secret. Can also be set via `ACCESS_SECRET` environment variable. Ensure the configuration file is secured if added to the file. When using implicit authentication, this option is not required.
### prefix
```yaml
prefix: string
```
Optional object prefix. Object storage doesn't have the concept of a directory but a prefix is similar. For example, a prefix could be `base/dir`. This helps with organizing data in an object storage bucket.
More can be found at the following links.
- [Organizing objects using prefixes](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-prefixes.html)
- [libcloud container method documentation](https://libcloud.readthedocs.io/en/stable/storage/api.html#libcloud.storage.base.StorageDriver.iterate_container_objects)
### host
```yaml
host: string
+25 -2
View File
@@ -15,6 +15,14 @@ Add custom storage engines via setting this parameter to the fully resolvable cl
Content storage specific settings are set with a corresponding configuration object having the same name as the content storage engine (i.e. duckdb or sqlite). These are optional and set to defaults if omitted.
### client
```yaml
schema: default database schema for the session - defaults to being
determined by the database
```
Additional settings for client-server databases. Also supported when the `content=url`.
### sqlite
```yaml
sqlite:
@@ -22,6 +30,8 @@ sqlite:
defaults to false
```
Additional settings for SQLite.
## objects
```yaml
objects: boolean|image|pickle
@@ -40,14 +50,27 @@ Object encoding options are:
functions: list
```
List of functions with user-defined SQL functions, only used when [content](#content) is enabled. Each list element must be one of the following:
List of functions with user-defined SQL functions. Each list element must be one of the following:
- function
- callable object
- dict with fields for name, argcount and function
- dict with fields for name, argcount, function and deterministic
[An example can be found here](../../query#custom-sql-functions).
## expressions
```yaml
expressions: list
```
List of expression shortcuts. Each list element must be a dict with the following fields.
- `name`: name of the expression
- `expression`: SQL expression, defaults to `name` when empty
- `index`: if this expression should have a database index, defaults to False when not provided
The expression can be a json data column, sql function or anything that can be run as a SQL snippet.
## query
```yaml
query:
+36 -4
View File
@@ -1,15 +1,35 @@
# General
General configuration options that don't fit elsewhere.
General configuration options.
## keyword
```yaml
keyword: boolean
keyword: boolean|string
```
Enables sparse keyword indexing for this embeddings.
When enabled, this parameter creates a BM25 index for full text search. It also implicitly disables the [defaults](../vectors/#defaults) setting for vector search.
When set to a boolean, this parameter creates a BM25 index for full text search. When set to a string, it expects a [keyword method](../scoring#method).
It also implicitly disables the [defaults](#defaults) setting for vector search.
## sparse
```yaml
sparse: boolean|path
```
Enables sparse vector indexing for this embeddings.
When set to `True`, this parameter creates a sparse vector index using the [default sparse index model](https://huggingface.co/prithivida/Splade_PP_en_v2). When set to a string, it expects a local or Hugging Face model path.
It also implicitly disables the [defaults](#defaults) setting for vector search.
## dense
```yaml
dense: boolean|string
```
Alias for the [vector model path](../vectors/#path). When set to `True`, the [default transformers vector model](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) is used.
## hybrid
```yaml
@@ -18,7 +38,14 @@ hybrid: boolean
Enables hybrid (sparse + dense) indexing for this embeddings.
When enabled, this parameter creates a BM25 index for full text search. It has no effect on the [defaults](../vectors/#defaults) or [path](../vectors/#path) settings.
When enabled, this parameter creates a BM25 index for full text search. It has no effect on the [defaults](#defaults) or [path](../vectors/#path) settings.
## defaults
```yaml
defaults: boolean
```
Uses default vector model path when enabled (default setting is True) and `path` is not provided. See [this link](../) for an example.
## indexes
```yaml
@@ -39,13 +66,18 @@ Sets the auto id generation method. When this is not set, an autogenerated numer
columns:
text: name of the text column
object: name of the object column
store: limit json data fields to this list of columns
```
Sets the `text` and `object` column names. Defaults to `text` and `object` if not provided.
`store` sets a list of columns to store in the JSON data field. When this isn't provided, all columns are stored (default). When `store` is set to `None`, no JSON columns are stored. This is useful is a field is only needed at indexing time but not search time.
## format
```yaml
format: json|pickle
```
Sets the configuration storage format. Defaults to `json`.
Note that `pickle` configuration is deprecated and will raise an error with the default settings. Its only kept for reading legacy indexes and requires setting the `ALLOW_PICKLE` environment variable. Only enable for local and/or trusted sources.
+10
View File
@@ -19,6 +19,8 @@ The `rdbms` backend has the following additional settings.
```yaml
url: database url connection string, alternatively can be set via the
GRAPH_URL environment variable
schema: database schema to store graph - defaults to being
determined by the database
nodes: table to store node data, defaults to `nodes`
edges: table to store edge data, defaults to `edges`
```
@@ -68,3 +70,11 @@ topics:
```
Enables topic modeling. Defaults are tuned so that in most cases these values don't need to be changed (except for categories). These parameters are available for advanced use cases where one wants full control over the community detection process.
## copyattributes
```yaml
copyattributes: boolean|list
```
Copy these attributes from input dictionaries in the `insert` method. If this is set to `True`, all attributes are copied. Otherwise, only the
attributes specified in this list are copied to the graph as attributes.
+91 -3
View File
@@ -12,11 +12,70 @@ The following covers the available options.
## method
```yaml
method: bm25|tfidf|sif|custom
method: bm25|tfidf|sif|pgtext|sparse|custom
```
Sets the scoring method. Add custom scoring via setting this parameter to the fully resolvable class string.
### pgtext
```yaml
schema: database schema to store keyword index - defaults to being
determined by the database
```
Additional settings for Postgres full-text keyword indexes.
### sparse
```yaml
path: sparse vector model path
vectormethod: vector embeddings method
vectornormalize: enable vector embeddings normalization (boolean)
gpu: boolean|int|string|device
normalize: enable score normalization (boolean|float|string|dict)
batch: Sets the transform batch size
encodebatch: Sets the encode batch size
vectors: additional model init args
encodeargs: additional encode() args
backend: ivfsparse|pgsparse|zvecsparse
```
Sparse vector scoring options. The sparse scoring instance combines a sparse vector model with a sparse approximate nearest neighbor index (ANN). This method supports both vector normalization and score normalization.
Vector normalization normalizes all vectors to have a magnitude of 1. By extension, all generated scores will be 0 to 1.
Score normalization scales the output between 0 and 1. This setting supports:
- `True` for default scale normalization
- `float` normalize using this as the scale factor
- `"bayes"` for Bayesian normalization using dynamic candidate score statistics
- `{method: "bayes", alpha: 1.0, beta: null}` for Bayesian normalization with optional custom parameters
#### ivfsparse
```yaml
ivfsparse:
sample: percent of data to use for model training (0.0 - 1.0)
nfeatures: top n features to use for model training, defaults to all features (int)
nlist: desired number of clusters (int)
nprobe: search probe setting (int)
minpoints: minimum number of points for a cluster (int)
```
Inverted file (IVF) index with flat vector file storage and sparse array support.
#### pgsparse
Sparse ANN backed by Postgres. Supports same options as the [pgvector](../ann/#pgvector) ANN.
#### zvecsparse
```yaml
zvecsparse:
efconstruction: ef_construction param for HnswIndexParam (int) - defaults to 200
m: number of HNSW links per element (int) - defaults to 50
efsearch: ef search param for HnswQueryParam (int) - defaults to 300
```
Sparse ANN backed by [zvec](https://github.com/alibaba/zvec). Stores sparse vectors in an embedded, path-based vector index. Requires the [ann](../../../install/#ann) extras package.
## terms
```yaml
terms: boolean|dict
@@ -32,9 +91,38 @@ Supports a `dict` with the parameters `cachelimit` and `cutoff`.
When `terms` is set to `True`, default parameters are used for the `cachelimit` and `cutoff`. Normally, these defaults are sufficient.
### Wildcard queries
Keyword queries containing `*` expand matching terms using SQL `LIKE`. Within these
expressions, `%` matches any sequence and `_` matches one character. To match a literal
percent sign, underscore or backslash, use `\%`, `\_` or `\\`, respectively.
For example, `report\_*` matches `report_2026`, while `report_*` also matches `reportX2026`.
Use a tokenizer that preserves these characters, such as `tokenizer: {whitespace: true}`,
or pass pre-tokenized query terms. Queries without `*` retain exact-term matching.
## normalize
```yaml
normalize: boolean
normalize: boolean|str|dict
```
Enables normalized scoring (ranging from 0 to 1). When enabled, statistics from the index will be used to calculate normalized scores.
Enables normalized scoring (ranging from 0 to 1). This setting supports:
- `True` for standard score normalization
- `"bayes"` | `"bb25"` for Bayesian normalization using dynamic candidate score statistics
- `{method: "bayes", alpha: 1.0, beta: null}` for Bayesian normalization with optional custom parameters
When standard normalization is enabled, statistics from the index are used to calculate normalized scores.
When Bayesian/BB25 normalization is enabled, it uses positive-score candidates, dynamic `beta=median(scores)`, adaptive
`alpha_eff=alpha/std(scores)` and a sigmoid transform (likelihood-only variant with flat prior) to map scores to `[0, 1]`.
Bayesian normalization references:
- [https://github.com/instructkr/bb25](https://github.com/instructkr/bb25)
- [https://github.com/cognica-io/bayesian-bm25](https://github.com/cognica-io/bayesian-bm25)
## tokenizer
```yaml
tokenizer: dict
```
Set tokenization rules. Passes these arguments to the underlying [Tokenization pipeline](../../../pipeline/data/tokenizer#txtai.pipeline.Tokenizer.__init__).
+75 -24
View File
@@ -10,54 +10,46 @@ path: string
Sets the path for a vectors model. When using a transformers/sentence-transformers model, this can be any model on the
[Hugging Face Hub](https://huggingface.co/models) or a local file path. Otherwise, it must be a local file path to a word embeddings model.
## defaults
```yaml
defaults: boolean
```
Uses default vector model path when enabled (default setting is True) and `path` is not provided. See [this link](../) for an example.
## method
```yaml
method: transformers|sentence-transformers|llama.cpp|litellm|external|words
method: transformers|sentence-transformers|llama.cpp|litellm|model2vec|external|
words
```
Embeddings method to use. If the method is not provided, it is inferred using the `path`.
`sentence-transformers`, `llama.cpp`, `litellm` and `words` require the [vectors](../../../install/#vectors) extras package to be installed.
`sentence-transformers`, `llama.cpp`, `litellm`, `model2vec` and `words` require the [vectors](../../../install/#vectors) extras package to be installed.
### transformers
Builds embeddings using a transformers model. While this can be any transformers model, it works best with
[models trained](https://huggingface.co/models?pipeline_tag=sentence-similarity) to build embeddings.
Both `mean` and `cls` pooling are supported and automatically inferred from the model. The pooling method can be overwritten by changing the method
from `transformers` to `meanpooling` or `clspooling` respectively.
`mean`, `cls`, `last`, `late` and `max` pooling are supported and automatically inferred from the model. The pooling method can be overwritten by changing the method from `transformers` to `meanpooling`, `clspooling`, `lastpooling`, `latepooling` or `maxpooling` respectively.
Setting `maxlength` to `True` enables truncating inputs to the `max_seq_length`. Setting `maxlength` to an integer will truncate inputs to that value. When omitted (default), the `maxlength` will be set to either the model or tokenizer maxlength.
Supports loading ONNX models directly. [See this section for more](../../../examples/#model-training).
### sentence-transformers
Same as transformers but loads models with the [sentence-transformers](https://github.com/UKPLab/sentence-transformers) library.
### llama.cpp
Builds embeddings using a llama.cpp model. Supports both local and remote GGUF paths on the HF Hub.
Builds embeddings using a [llama.cpp](https://github.com/abetlen/llama-cpp-python) model. Supports both local and remote GGUF paths on the HF Hub.
### litellm
Builds embeddings using a LiteLLM model. See the [LiteLLM documentation](https://litellm.vercel.app/docs/providers) for the options available with LiteLLM models.
### model2vec
Builds embeddings using a [Model2Vec](https://github.com/MinishLab/model2vec) model. Model2Vec is a knowledge-distilled version of a transformers model with static vectors.
### words
Builds embeddings using a word embeddings model. Transformers models are the preferred vector backend in most cases. Word embeddings models may be deprecated in the future.
#### storevectors
```yaml
storevectors: boolean
```
Enables copying of a vectors model set in path into the embeddings models output directory on save. This option enables a fully encapsulated index with no external file dependencies.
Builds embeddings using a word embeddings model and static vectors. While Transformers models are preferred in most cases, this method can be useful for low resource and historical languages where there isn't much linguistic data available.
#### pca
```yaml
@@ -75,7 +67,9 @@ Embeddings are created via an external model or API. Requires setting the [trans
transform: function
```
When method is `external`, this function transforms input content into embeddings. The input to this function is a list of data. This method must return either a numpy array or list of numpy arrays.
When method is `external`, this function transforms input content into embeddings. The input to this function is a list of data. This method must return either a numpy array, list of numpy arrays or list of float arrays.
Note that this method is deprecated and will raise an error with the default settings. Adding a custom `Vectors` implementation is a cleaner approach. The `ALLOW_RESOLVE_TRANSFORM` environment variable must be set to enable. Only enable for trusted and/or reviewed code.
## gpu
```yaml
@@ -84,6 +78,8 @@ gpu: boolean|int|string|device
Set the target device. Supports true/false, device id, device string and torch device instance. This is automatically derived if omitted.
The `sentence-transformers` method supports encoding with multiple GPUs. This can be enabled by setting the gpu parameter to `all`.
## batch
```yaml
batch: int
@@ -110,9 +106,9 @@ Enables truncation of vectors to this dimensionality. This is only useful for mo
quantize: int|boolean
```
Enables scalar vector quantization at the specified precision. Supports 1-bit through 8-bit quantization. Scalar quantization transforms continuous floating point values to discrete unsigned integers. Only the `faiss`, `numpy` and `torch` ANN backends support storing these vectors.
Enables scalar vector quantization at the specified precision. Supports 1-bit through 8-bit quantization. Scalar quantization transforms continuous floating point values to discrete unsigned integers. The `faiss`, `pgvector`, `numpy` and `torch` ANN backends support storing these vectors.
This parameter supports booleans for backwards compatability. When set to true/false, this flag sets [faiss.quantize](../ann/#faiss).
This parameter supports booleans for backwards compatibility. When set to true/false, this flag sets [faiss.quantize](../ann/#faiss).
In addition to vector-level quantization, some ANN backends have the ability to quantize vectors at the storage layer. See the [ANN](../ann) configuration options for more.
@@ -125,7 +121,7 @@ instructions:
Instruction-based models use prefixes to modify how embeddings are computed. This is especially useful with asymmetric search, which is when the query and indexed data are of vastly different lengths. In other words, short queries with long documents.
[E5-base](https://huggingface.co/intfloat/e5-base) is an example of a model that accepts instructions. It takes `query: ` and `passage: ` prefixes and uses those to generate embeddings that work well for asymmetric search.
`txtai` automatically loads prompts stored in `config_sentence_transformers.json` except if this parameter is set. For some older models such as [E5-base](https://huggingface.co/intfloat/e5-base), instructions still need to be provided via this parameter.
## models
```yaml
@@ -147,3 +143,58 @@ vectors: dict
```
Passes these additional parameters to the underlying vector model.
### center
```yaml
center: boolean | dict
```
Centers normalized late-interaction token vectors and normalizes them again before MUVERA or LEMUR encoding. Centering is applied to
both query and document vectors. `true` uses batch scope and `false` disables centering. An explicit setting always takes precedence.
When omitted, a LEMUR artifact with a stored collection mean uses collection scope. Other LEMUR artifacts and late-interaction models
default to batch scope only when they load more than one `torch.nn.Linear` layer; models with zero or one loaded linear layer keep their
previous output.
Dictionary configuration supports the following scopes:
```yaml
center:
scope: document | batch | collection
```
`document` subtracts the mean of each document or query independently. `batch` subtracts the mean of all real token rows in the current
model batch. Explicit `collection` scope requires a caller-provided, one-dimensional mean vector through either `mean` (an array-like
value) or `path` (a safetensors file containing a `center.mean` tensor), but not both. LEMUR artifacts can provide this mean
automatically. Zero-padding rows are never centered and remain zero.
### muvera
```yaml
muvera:
repetitions: defaults 20
hashes: defaults to 5
projection: defaults 16
```
Settings to control the size of MUVERA fixed dimensional outputs. Default is 20 * 2^5 * 16 = 10,240 dimensions.
Set `muvera` to `false` to disable it or `true` to use the default settings. `false` only makes sense when the multi-vector output
is consumed directly, for example through `PoolingFactory`. Embeddings vectors require `muvera` or `lemur`.
### lemur
```yaml
lemur:
path: local artifact directory or Hugging Face Hub path
```
Loads a trained [LEMUR](../../../pipeline/train/lemur) fixed dimensional encoder. LEMUR artifacts are corpus-specific and must be
created with `LemurTrainer` before configuring an embeddings index. A bare string is treated as the artifact path. Query vectors are
summed learned features and document vectors are ordinary least squares weights over the artifact's stored token sample. Each artifact
contains `config.json` and `model.safetensors`; newly trained artifacts also store the collection token mean as `lemur.center`. Loading that mean automatically
selects collection centering unless `center` is explicitly configured. Artifacts without `lemur.center` retain the previous default.
The Safetensors file contains inference state only. See the trainer page for score filtering and Faiss exact/IVF search behavior.
### trust_remote_code
```yaml
trust_remote_code: boolean
```
Parameter for trusting the code from Hugging Face models with custom implementations.
+17
View File
@@ -100,6 +100,23 @@ The search method takes two parameters, the query and query limit. The results f
Both natural language and SQL queries are supported. More information can be found in the [query guide](query).
## Resource management
Embeddings databases are context managers. The following blocks automatically [close](methods/#txtai.embeddings.base.Embeddings.close) and free resources upon completion.
```python
# Create a new Embeddings database, index data and save
with Embeddings() as embeddings:
embeddings.index(rows)
embeddings.save(path)
# Search a saved Embeddings database
with Embeddings().load(path) as embeddings:
embeddings.search(query)
```
While calling `close` isn't always necessary (resources will be garbage collected), it's best to free shared resources like database connections as soon as they aren't needed.
## More examples
See [this link](../examples/#semantic-search) for a full list of embeddings examples.
+3 -1
View File
@@ -23,6 +23,8 @@ As mentioned above, computed vectors are stored in an ANN. There are various ind
Embeddings indexes can optionally [store content](../configuration/database#content). When this is enabled, the input content is saved in a database alongside the computed vectors. This enables filtering on additional fields and content retrieval.
The columns used for text, object and JSON data storage are set via [column configuration](../configuration/general#columns).
## Index vs Upsert
Data is loaded into an index with either an [index](../methods#txtai.embeddings.base.Embeddings.index) or [upsert](../methods#txtai.embeddings.base.Embeddings.upsert) call.
@@ -112,7 +114,7 @@ Graphs are persisted alongside an embeddings index. Each save and load will also
## Sparse vectors
Scoring instances can create a standalone [keyword](../configuration/general#keyword) or sparse index (BM25, TF-IDF). This enables [hybrid](../configuration/general/#hybrid) search when there is an available dense vector index.
Scoring instances can create a standalone [sparse keyword indexes](../configuration/general#keyword) (BM25, TF-IDF) and [sparse vector indexes](../configuration/general#sparse) (SPLADE). This enables [hybrid](../configuration/general/#hybrid) search when there is an available dense vector index.
The terms `sparse vector index`, `keyword index`, `terms index` and `scoring index` are used interchangeably throughout txtai's documentation.
+57 -6
View File
@@ -54,6 +54,8 @@ The number of candidates should be larger than the desired number of results whe
- For a single query filter clause, the default is the query limit
- With multiple filtering clauses, the default is 10x the query limit
When a query orders results by score, its `offset` adds to the query limit.
The index name is only applicable when [subindexes](../configuration/general/#indexes) are enabled. This specifies the index to use for the query.
Weights sets the hybrid score weights when an index has both a sparse and dense index.
@@ -132,8 +134,11 @@ embeddings = Embeddings(content=True, objects=True)
request = open("demo.gif", "rb")
# Insert record
embeddings.index([("txtai", {"text": "txtai executes machine-learning workflows.",
"object": request.read()})])
embeddings.index([(
"txtai",
{"text": "txtai executes machine-learning workflows.",
"object": request.read()}
)])
# Query txtai and get associated object
query = "SELECT object FROM txtai WHERE similar('machine learning') LIMIT 1"
@@ -169,6 +174,26 @@ LIMIT 1
""")
```
## Expressions
Expression shortcuts expand into more complex SQL snippets. This is useful for making SQL queries more concise. Indexing is also available on expressions as a performance improvement.
The following example indexes a json extraction field (`filepath`) and the length of each field.
```python
# Create embeddings index
embeddings = Embeddings(
path="sentence-transformers/nli-mpnet-base-v2",
content=True,
expressions=[
{"name": "filepath", "index": True},
{"name": "textlength", "expression": "length(text)", "index": True}
]
)
embeddings.search("SELECT textlength, filepath FROM txtai LIMIT 1")
```
## Query translation
Natural language queries with filters can be converted to txtai-compatible SQL statements with query translation. For example:
@@ -192,7 +217,9 @@ When an embeddings database has both a sparse and dense index, both indexes will
```python
embeddings.search("query", weights=0.5)
embeddings.search("SELECT id, text, score FROM txtai WHERE similar('query', 0.5)")
embeddings.search(
"SELECT id, text, score FROM txtai WHERE similar('query', 0.5)"
)
```
## Graph search
@@ -203,11 +230,20 @@ Additionally, standard embeddings searches can be returned as graphs.
```python
# Find all paths between id: 0 and id: 5 between 1 and 3 hops away
embeddings.graph.search("""
embeddings.search("""
MATCH P=({id: 0})-[*1..3]->({id: 5})
RETURN P
""")
# Find related nodes for query matches
embeddings.search("""
MATCH P=(A)-[]->(B)
WHERE SIMILAR(A, "query")
RETURN B
ORDER BY A.score DESC
LIMIT 10
""")
# Standard embeddings search as graph
embeddings.search("query", graph=True)
```
@@ -217,13 +253,28 @@ embeddings.search("query", graph=True)
Subindexes can be queried as follows:
```python
# Build index with subindexes
embeddings = Embeddings(
content=True,
defaults=False,
indexes={
"keyword": {
"keyword": True
},
"dense":{
"dense": True
}
}
)
embeddings.index(stream())
# Query with index parameter
embeddings.search("query", index="subindex1")
embeddings.search("query", index="keyword")
# Specify with SQL
embeddings.search("""
SELECT id, text, score FROM txtai
WHERE similar('query', 'subindex1')
WHERE similar('query', 'keyword')
""")
```
+26 -4
View File
@@ -25,13 +25,13 @@ Build semantic/similarity/vector/neural search applications.
## LLM
LLM chains, retrieval augmented generation (RAG), chat with your data, pipelines and workflows that interface with large language models (LLMs).
Autonomous agents, retrieval augmented generation (RAG), chat with your data, pipelines and workflows that interface with large language models (LLMs).
| Notebook | Description | |
|:----------|:-------------|------:|
| [Prompt-driven search with LLMs](https://github.com/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) | Embeddings-guided and Prompt-driven search with Large Language Models (LLMs) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) |
| [Prompt templates and task chains](https://github.com/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) | Build model prompts and connect tasks together with workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) [▶️](https://www.youtube.com/watch?v=t_OeAc8NVfQ) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [Integrate LLM frameworks](https://github.com/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) | Integrate llama.cpp, LiteLLM and custom generation frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) |
| [Generate knowledge with Semantic Graphs and RAG](https://github.com/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) | Knowledge exploration and discovery with Semantic Graphs and RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) |
| [Build knowledge graphs with LLMs](https://github.com/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) | Build knowledge graphs with LLM-driven entity extraction | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) |
@@ -39,6 +39,20 @@ LLM chains, retrieval augmented generation (RAG), chat with your data, pipelines
| [Advanced RAG with guided generation](https://github.com/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) | Retrieval Augmented and Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) |
| [RAG with llama.cpp and external API services](https://github.com/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) | RAG with additional vector and LLM frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) |
| [How RAG with txtai works](https://github.com/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) | Create RAG processes, API services and Docker instances | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) |
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
| [Analyzing Hugging Face Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) | Explore a rich dataset with Graph Analysis and Agents | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) |
| [Granting autonomy to agents](https://github.com/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) | Agents that iteratively solve problems as they see fit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) |
| [Getting started with LLM APIs](https://github.com/neuml/txtai/blob/master/examples/70_Getting_started_with_LLM_APIs.ipynb) | Generate embeddings and run LLMs with OpenAI, Claude, Gemini, Bedrock and more | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/70_Getting_started_with_LLM_APIs.ipynb) |
| [Analyzing LinkedIn Company Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) | Exploring how to improve social media engagement with AI | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) |
| [Parsing the stars with txtai](https://github.com/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) | Explore an astronomical knowledge graph of known stars, planets, galaxies | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) |
| [Chunking your data for RAG](https://github.com/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) | Extract, chunk and index content for effective retrieval | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) |
| [Medical RAG Research with txtai](https://github.com/neuml/txtai/blob/master/examples/75_Medical_RAG_Research_with_txtai.ipynb) | Analyze PubMed article metadata with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/75_Medical_RAG_Research_with_txtai.ipynb) |
| [GraphRAG with Wikipedia and GPT OSS](https://github.com/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) | Deep graph search powered RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) |
| [RAG is more than Vector Search](https://github.com/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) | Context retrieval via Web, SQL and other sources | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) |
| [OpenCode as a txtai LLM](https://github.com/neuml/txtai/blob/master/examples/81_OpenCode_as_a_txtai_LLM.ipynb) | Integrate OpenCode with the txtai ecosystem | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/81_OpenCode_as_a_txtai_LLM.ipynb) |
| [Agentic College Search](https://github.com/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) | Identify a list of strong engineering colleges | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) |
| [TxtAI got skills](https://github.com/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) | Integrate skill.md files with your agent | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) |
| [Agent Tools](https://github.com/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) [▶️](https://www.youtube.com/watch?v=RDNaFXQy3GQ) | Learn about the txtai agent toolkit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) |
## Pipelines
@@ -72,10 +86,11 @@ Efficiently process data at scale.
| [Push notifications with workflows](https://github.com/neuml/txtai/blob/master/examples/28_Push_notifications_with_workflows.ipynb) | Generate and push notifications with workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/28_Push_notifications_with_workflows.ipynb) |
| [Pictures are a worth a thousand words](https://github.com/neuml/txtai/blob/master/examples/35_Pictures_are_worth_a_thousand_words.ipynb) | Generate webpage summary images with DALL-E mini | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/35_Pictures_are_worth_a_thousand_words.ipynb) |
| [Run txtai with native code](https://github.com/neuml/txtai/blob/master/examples/36_Run_txtai_in_native_code.ipynb) | Execute workflows in native code with the Python C API | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/36_Run_txtai_in_native_code.ipynb) |
| [Generative Audio](https://github.com/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) | Storytelling with generative audio workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) |
## Model Training
Train NLP models.
Train, distill, fine-tune and export models.
| Notebook | Description | |
|:----------|:-------------|------:|
@@ -83,6 +98,8 @@ Train NLP models.
| [Train without labels](https://github.com/neuml/txtai/blob/master/examples/17_Train_without_labels.ipynb) | Use zero-shot classifiers to train new models | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/17_Train_without_labels.ipynb) |
| [Train a QA model](https://github.com/neuml/txtai/blob/master/examples/19_Train_a_QA_model.ipynb) | Build and fine-tune question-answering models | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/19_Train_a_QA_model.ipynb) |
| [Train a language model from scratch](https://github.com/neuml/txtai/blob/master/examples/41_Train_a_language_model_from_scratch.ipynb) | Build new language models | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/41_Train_a_language_model_from_scratch.ipynb) |
| [Distilling Knowledge into Tiny LLMs](https://github.com/neuml/txtai/blob/master/examples/80_Distilling_Knowledge_into_Tiny_LLMs.ipynb) [▶️](https://www.youtube.com/watch?v=Ol560ktgkf0) | Finetune tiny LLMs to enable inference using less resources | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/80_Distilling_Knowledge_into_Tiny_LLMs.ipynb) |
| [Progressive Distillation](https://github.com/neuml/txtai/blob/master/examples/85_Progressive_Distillation.ipynb) | Incrementally compress knowledge from a series of teachers | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/85_Progressive_Distillation.ipynb) |
| [Export and run models with ONNX](https://github.com/neuml/txtai/blob/master/examples/18_Export_and_run_models_with_ONNX.ipynb) | Export models with ONNX, run natively in JavaScript, Java and Rust | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/18_Export_and_run_models_with_ONNX.ipynb) |
| [Export and run other machine learning models](https://github.com/neuml/txtai/blob/master/examples/21_Export_and_run_other_machine_learning_models.ipynb) | Export and run models from scikit-learn, PyTorch and more | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/21_Export_and_run_other_machine_learning_models.ipynb) |
@@ -97,6 +114,7 @@ Run distributed txtai, integrate with the API and cloud endpoints.
| [Embeddings in the Cloud](https://github.com/neuml/txtai/blob/master/examples/43_Embeddings_in_the_Cloud.ipynb) | Load and use an embeddings index from the Hugging Face Hub | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/43_Embeddings_in_the_Cloud.ipynb) |
| [Custom API Endpoints](https://github.com/neuml/txtai/blob/master/examples/51_Custom_API_Endpoints.ipynb) | Extend the API with custom endpoints | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/51_Custom_API_Endpoints.ipynb) |
| [API Authorization and Authentication](https://github.com/neuml/txtai/blob/master/examples/54_API_Authorization_and_Authentication.ipynb) | Add authorization, authentication and middleware dependencies to the API | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/54_API_Authorization_and_Authentication.ipynb) |
| [OpenAI Compatible API](https://github.com/neuml/txtai/blob/master/examples/74_OpenAI_Compatible_API.ipynb) | Connect to txtai with a standard OpenAI client library | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/74_OpenAI_Compatible_API.ipynb) |
## Architecture
@@ -107,12 +125,14 @@ Project architecture, data formats, external integrations, scale to production,
| [Anatomy of a txtai index](https://github.com/neuml/txtai/blob/master/examples/29_Anatomy_of_a_txtai_index.ipynb) | Deep dive into the file formats behind a txtai embeddings index | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/29_Anatomy_of_a_txtai_index.ipynb) |
| [Embeddings components](https://github.com/neuml/txtai/blob/master/examples/37_Embeddings_index_components.ipynb) | Composable search with vector, SQL and scoring components | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/37_Embeddings_index_components.ipynb) |
| [Customize your own embeddings database](https://github.com/neuml/txtai/blob/master/examples/45_Customize_your_own_embeddings_database.ipynb) | Ways to combine vector indexes with relational databases | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/45_Customize_your_own_embeddings_database.ipynb) |
| [Building an efficient sparse keyword index in Python](https://github.com/neuml/txtai/blob/master/examples/47_Building_an_efficient_sparse_keyword_index_in_Python.ipynb) | Fast and accurate sparse keyword indexing | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/48_Benefits_of_hybrid_search.ipynb) |
| [Building an efficient sparse keyword index in Python](https://github.com/neuml/txtai/blob/master/examples/47_Building_an_efficient_sparse_keyword_index_in_Python.ipynb) | Fast and accurate sparse keyword indexing | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/47_Building_an_efficient_sparse_keyword_index_in_Python.ipynb) |
| [Benefits of hybrid search](https://github.com/neuml/txtai/blob/master/examples/48_Benefits_of_hybrid_search.ipynb) | Improve accuracy with a combination of semantic and keyword search | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/48_Benefits_of_hybrid_search.ipynb) |
| [External database integration](https://github.com/neuml/txtai/blob/master/examples/49_External_database_integration.ipynb) | Store metadata in PostgreSQL, MariaDB, MySQL and more | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/49_External_database_integration.ipynb) |
| [All about vector quantization](https://github.com/neuml/txtai/blob/master/examples/50_All_about_vector_quantization.ipynb) | Benchmarking scalar and product quantization methods | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/50_All_about_vector_quantization.ipynb) |
| [External vectorization](https://github.com/neuml/txtai/blob/master/examples/56_External_vectorization.ipynb) | Vectorization with precomputed embeddings datasets and APIs | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/56_External_vectorization.ipynb) |
| [Integrate txtai with Postgres](https://github.com/neuml/txtai/blob/master/examples/61_Integrate_txtai_with_Postgres.ipynb) | Persist content, vectors and graph data in Postgres | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/61_Integrate_txtai_with_Postgres.ipynb) |
| [Embeddings index format for open data access](https://github.com/neuml/txtai/blob/master/examples/64_Embeddings_index_format_for_open_data_access.ipynb) | Platform and programming language independent data storage with txtai | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/64_Embeddings_index_format_for_open_data_access.ipynb) |
| [Accessing Low Level Vector APIs](https://github.com/neuml/txtai/blob/master/examples/78_Accessing_Low_Level_Vector_APIs.ipynb) | Build a vector database using txtai's low-level APIs | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/78_Accessing_Low_Level_Vector_APIs.ipynb) |
## Releases
@@ -123,6 +143,8 @@ New functionality added in major releases.
| [What's new in txtai 4.0](https://github.com/neuml/txtai/blob/master/examples/24_Whats_new_in_txtai_4_0.ipynb) | Content storage, SQL, object storage, reindex and compressed indexes | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/24_Whats_new_in_txtai_4_0.ipynb) |
| [What's new in txtai 6.0](https://github.com/neuml/txtai/blob/master/examples/46_Whats_new_in_txtai_6_0.ipynb) | Sparse, hybrid and subindexes for embeddings, LLM improvements | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/46_Whats_new_in_txtai_6_0.ipynb) |
| [What's new in txtai 7.0](https://github.com/neuml/txtai/blob/master/examples/59_Whats_new_in_txtai_7_0.ipynb) | Semantic graph 2.0, LoRA/QLoRA training and binary API support | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/59_Whats_new_in_txtai_7_0.ipynb) |
| [What's new in txtai 8.0](https://github.com/neuml/txtai/blob/master/examples/67_Whats_new_in_txtai_8_0.ipynb) | Agents with txtai | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/67_Whats_new_in_txtai_8_0.ipynb) |
| [What's new in txtai 9.0](https://github.com/neuml/txtai/blob/master/examples/76_Whats_new_in_txtai_9_0.ipynb) | Learned sparse vectors, late interaction models and rerankers | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/76_Whats_new_in_txtai_9_0.ipynb) |
## Applications
+11 -6
View File
@@ -30,11 +30,13 @@ Wrap the list or generator passed to the index call with tqdm. See [#478](https:
__Question__
What is the best way to analyze the content of a txtai index?
What is the best way to analyze and debug a txtai process?
__Answer__
txtai has a console application that makes this easy. Read [this article](https://medium.com/neuml/insights-from-the-txtai-console-d307c28e149e) to learn more.
See the [observability](../observability) section for more on how this can be enabled in txtai processes.
txtai also has a console application. [This article](https://medium.com/neuml/insights-from-the-txtai-console-d307c28e149e) has more details.
----------
@@ -66,11 +68,11 @@ import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from txtai import LLM
# Load Mistral-7B-OpenOrca
path = "Open-Orca/Mistral-7B-OpenOrca"
# Load Qwen3 0.6B
path = "Qwen/Qwen3-0.6B"
model = AutoModelForCausalLM.from_pretrained(
path,
torch_dtype=torch.bfloat16,
dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(path)
@@ -103,10 +105,13 @@ __Solution__
Set the following environment parameters.
- Disable OpenMP threading via the environment variable `export OMP_NUM_THREADS=1`
- Disable OpenMP multithreading via `export OMP_NUM_THREADS=1`
- Workaround `OMP: Error #15` errors via `export KMP_DUPLICATE_LIB_OK=TRUE`
- Disable PyTorch MPS device via `export PYTORCH_MPS_DISABLE=1`
- Disable llama.cpp metal via `export LLAMA_NO_METAL=1`
For more details, refer to [this issue on GitHub](https://github.com/kyamagu/faiss-wheels/issues/73).
----------
__Issue__
+3 -2
View File
@@ -3,9 +3,10 @@
![further](images/further.png#only-light)
![further](images/further-dark.png#only-dark)
- [Introducing txtai, the all-in-one embeddings database](https://medium.com/neuml/introducing-txtai-the-all-in-one-embeddings-database-c721f4ff91ad)
- [Introducing txtai, the all-in-one AI framework](https://medium.com/neuml/introducing-txtai-the-all-in-one-ai-framework-0660ecfc39d7)
- [txtai: An All-in-One AI Framework for Semantic Search and LLM Workflows](https://github.com/neuml/papers/blob/master/txtai/txtai.pdf)
- [Tutorial series on Hashnode](https://neuml.hashnode.dev/series/txtai-tutorial) | [dev.to](https://dev.to/neuml/tutorial-series-on-txtai-ibg)
- [What's new in txtai 7.0](https://medium.com/neuml/whats-new-in-txtai-7-0-855ad6a55440) | [6.0](https://medium.com/neuml/whats-new-in-txtai-6-0-7d93eeedf804) | [5.0](https://medium.com/neuml/whats-new-in-txtai-5-0-e5c75a13b101) | [4.0](https://medium.com/neuml/whats-new-in-txtai-4-0-bbc3a65c3d1c)
- [What's new in txtai 9.0](https://medium.com/neuml/whats-new-in-txtai-9-0-d522bb150afa) | [8.0](https://medium.com/neuml/whats-new-in-txtai-8-0-2d7d0ab4506b) | [7.0](https://medium.com/neuml/whats-new-in-txtai-7-0-855ad6a55440) | [6.0](https://medium.com/neuml/whats-new-in-txtai-6-0-7d93eeedf804) | [5.0](https://medium.com/neuml/whats-new-in-txtai-5-0-e5c75a13b101) | [4.0](https://medium.com/neuml/whats-new-in-txtai-4-0-bbc3a65c3d1c)
- [Getting started with semantic search](https://medium.com/neuml/getting-started-with-semantic-search-a9fd9d8a48cf) | [workflows](https://medium.com/neuml/getting-started-with-semantic-workflows-2fefda6165d9) | [rag](https://medium.com/neuml/getting-started-with-rag-9a0cca75f748)
- [Running txtai at scale](https://medium.com/neuml/running-at-scale-with-txtai-71196cdd99f9)
- [Vector search & RAG Landscape: A review with txtai](https://medium.com/neuml/vector-search-rag-landscape-a-review-with-txtai-a7f37ad0e187)
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB

After

Width:  |  Height:  |  Size: 434 KiB

+284 -157
View File
@@ -5,8 +5,8 @@
"elements": [
{
"type": "rectangle",
"version": 633,
"versionNonce": 705603336,
"version": 639,
"versionNonce": 1876686474,
"isDeleted": false,
"id": "mG5J3YEl3JUm8tWD2gLax",
"fillStyle": "hachure",
@@ -15,22 +15,29 @@
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 840.1017043524607,
"x": 840.0920889678455,
"y": 323.8650942251963,
"strokeColor": "#ff7043",
"backgroundColor": "#ff7043",
"width": 412.0000000000001,
"height": 54.999999999999964,
"seed": 322487816,
"groupIds": [],
"groupIds": [
"VYua_NGvuS1eX_KPHCgOc"
],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1641744014625
"updated": 1731084295790,
"index": "a4",
"frameId": null,
"roundness": null,
"link": null,
"locked": false
},
{
"type": "text",
"version": 202,
"versionNonce": 1087974776,
"version": 210,
"versionNonce": 82579222,
"isDeleted": false,
"id": "N9ytCRthOA395FeHYtiWS",
"fillStyle": "hachure",
@@ -39,17 +46,19 @@
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 1010.3997812755383,
"x": 1019.5920889678455,
"y": 335.8362480713501,
"strokeColor": "#343a40",
"backgroundColor": "#03a9f4",
"width": 53,
"height": 36,
"seed": 1396884744,
"groupIds": [],
"groupIds": [
"VYua_NGvuS1eX_KPHCgOc"
],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1641744014625,
"updated": 1731084295790,
"fontSize": 28,
"fontFamily": 1,
"text": "API",
@@ -57,138 +66,19 @@
"textAlign": "left",
"verticalAlign": "top",
"containerId": null,
"originalText": "API"
"originalText": "API",
"index": "a5",
"frameId": null,
"roundness": null,
"link": null,
"locked": false,
"autoResize": true,
"lineHeight": 1.2857142857142858
},
{
"type": "rectangle",
"version": 741,
"versionNonce": 917800456,
"isDeleted": false,
"id": "uFbzRXgEesWgll3llORrW",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 839.3613197370764,
"y": 387.49009422519623,
"strokeColor": "#00e676",
"backgroundColor": "#00e676",
"width": 184,
"height": 60.846153846153825,
"seed": 531948552,
"groupIds": [],
"strokeSharpness": "sharp",
"boundElements": [
{
"type": "text",
"id": "Ctud-Ap642NinH0-64fKT"
}
],
"updated": 1641744014625
},
{
"type": "text",
"version": 509,
"versionNonce": 171632136,
"isDeleted": false,
"id": "Ctud-Ap642NinH0-64fKT",
"fillStyle": "cross-hatch",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 844.3613197370764,
"y": 399.91317114827314,
"strokeColor": "#000000",
"backgroundColor": "#03a9f4",
"width": 174,
"height": 36,
"seed": 720254072,
"groupIds": [],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1641743551018,
"fontSize": 28,
"fontFamily": 1,
"text": "Pipeline",
"baseline": 25,
"textAlign": "center",
"verticalAlign": "middle",
"containerId": "uFbzRXgEesWgll3llORrW",
"originalText": "Pipeline"
},
{
"type": "rectangle",
"version": 726,
"versionNonce": 558153336,
"isDeleted": false,
"id": "_zQO_kyS5Pvq1zDhEn9hv",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 1032.3805505063074,
"y": 389.3362480713501,
"strokeColor": "#ffeb3b",
"backgroundColor": "#ffeb3b",
"width": 219,
"height": 56,
"seed": 1988829960,
"groupIds": [],
"strokeSharpness": "sharp",
"boundElements": [
{
"id": "tL_gw7MpliV1bDFJp8Cql",
"type": "text"
},
{
"type": "text",
"id": "tL_gw7MpliV1bDFJp8Cql"
}
],
"updated": 1641744014625
},
{
"type": "text",
"version": 514,
"versionNonce": 1694557448,
"isDeleted": false,
"id": "tL_gw7MpliV1bDFJp8Cql",
"fillStyle": "cross-hatch",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 1037.2555505063074,
"y": 399.3362480713501,
"strokeColor": "#000000",
"backgroundColor": "#03a9f4",
"width": 209,
"height": 36,
"seed": 274132856,
"groupIds": [],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1641743551018,
"fontSize": 28,
"fontFamily": 1,
"text": "Workflow",
"baseline": 25,
"textAlign": "center",
"verticalAlign": "middle",
"containerId": "_zQO_kyS5Pvq1zDhEn9hv",
"originalText": "Workflow"
},
{
"type": "rectangle",
"version": 455,
"versionNonce": 289834248,
"version": 460,
"versionNonce": 1551291798,
"isDeleted": false,
"id": "QKBksUpSSix31GSKFO1uV",
"fillStyle": "hachure",
@@ -197,8 +87,8 @@
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 838.5920889678456,
"y": 456.87470960981165,
"x": 837.5920889678456,
"y": 456.8747096098117,
"strokeColor": "#03a9f4",
"backgroundColor": "#03a9f4",
"width": 417,
@@ -210,22 +100,19 @@
{
"id": "4o-d8ZzuqEpB7ROBAyReL",
"type": "text"
},
{
"id": "4o-d8ZzuqEpB7ROBAyReL",
"type": "text"
},
{
"type": "text",
"id": "4o-d8ZzuqEpB7ROBAyReL"
}
],
"updated": 1641744014625
"updated": 1731084298697,
"index": "a6",
"frameId": null,
"roundness": null,
"link": null,
"locked": false
},
{
"type": "text",
"version": 258,
"versionNonce": 347014152,
"version": 263,
"versionNonce": 1011157002,
"isDeleted": false,
"id": "4o-d8ZzuqEpB7ROBAyReL",
"fillStyle": "cross-hatch",
@@ -234,8 +121,8 @@
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 843.4670889678456,
"y": 469.29778653288855,
"x": 842.4670889678456,
"y": 469.2977865328886,
"strokeColor": "#343a40",
"backgroundColor": "#03a9f4",
"width": 407,
@@ -244,7 +131,7 @@
"groupIds": [],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1641743551019,
"updated": 1731084298697,
"fontSize": 28,
"fontFamily": 1,
"text": "Embeddings",
@@ -252,11 +139,251 @@
"textAlign": "center",
"verticalAlign": "middle",
"containerId": "QKBksUpSSix31GSKFO1uV",
"originalText": "Embeddings"
"originalText": "Embeddings",
"index": "a7",
"frameId": null,
"roundness": null,
"link": null,
"locked": false,
"autoResize": true,
"lineHeight": 1.2857142857142858
},
{
"type": "rectangle",
"version": 847,
"versionNonce": 266827407,
"isDeleted": false,
"id": "uFbzRXgEesWgll3llORrW",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 969.4670889678455,
"y": 387.5069211482732,
"strokeColor": "#00e676",
"backgroundColor": "#00e676",
"width": 135,
"height": 60.846153846153825,
"seed": 531948552,
"groupIds": [
"DlS9eiqyrIHp45FmS35GN"
],
"strokeSharpness": "sharp",
"boundElements": [
{
"type": "text",
"id": "Ctud-Ap642NinH0-64fKT"
}
],
"updated": 1731149308913,
"index": "a8",
"frameId": null,
"roundness": null,
"link": null,
"locked": false
},
{
"type": "text",
"version": 617,
"versionNonce": 1566326241,
"isDeleted": false,
"id": "Ctud-Ap642NinH0-64fKT",
"fillStyle": "cross-hatch",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 988.8004223011789,
"y": 399.9299980713501,
"strokeColor": "#000000",
"backgroundColor": "#03a9f4",
"width": 96.33333333333333,
"height": 36,
"seed": 720254072,
"groupIds": [
"DlS9eiqyrIHp45FmS35GN"
],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1731149308913,
"fontSize": 28,
"fontFamily": 1,
"text": "Pipeline",
"baseline": 25,
"textAlign": "center",
"verticalAlign": "middle",
"containerId": "uFbzRXgEesWgll3llORrW",
"originalText": "Pipeline",
"index": "a9",
"frameId": null,
"roundness": null,
"link": null,
"locked": false,
"autoResize": true,
"lineHeight": 1.2857142857142858
},
{
"type": "rectangle",
"version": 827,
"versionNonce": 1640467681,
"isDeleted": false,
"id": "_zQO_kyS5Pvq1zDhEn9hv",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 1111.4863197370764,
"y": 388.1766044061918,
"strokeColor": "#ffeb3b",
"backgroundColor": "#ffeb3b",
"width": 141,
"height": 59.76470588235287,
"seed": 1988829960,
"groupIds": [
"DlS9eiqyrIHp45FmS35GN"
],
"strokeSharpness": "sharp",
"boundElements": [
{
"id": "tL_gw7MpliV1bDFJp8Cql",
"type": "text"
}
],
"updated": 1731149323000,
"index": "aA",
"frameId": null,
"roundness": null,
"link": null,
"locked": false
},
{
"type": "text",
"version": 617,
"versionNonce": 1776634049,
"isDeleted": false,
"id": "tL_gw7MpliV1bDFJp8Cql",
"fillStyle": "cross-hatch",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 1122.7113197370763,
"y": 400.0589573473683,
"strokeColor": "#000000",
"backgroundColor": "#03a9f4",
"width": 118.55,
"height": 36,
"seed": 274132856,
"groupIds": [
"DlS9eiqyrIHp45FmS35GN"
],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1731149323001,
"fontSize": 28,
"fontFamily": 1,
"text": "Workflow",
"baseline": 25,
"textAlign": "center",
"verticalAlign": "middle",
"containerId": "_zQO_kyS5Pvq1zDhEn9hv",
"originalText": "Workflow",
"index": "aB",
"frameId": null,
"roundness": null,
"link": null,
"locked": false,
"autoResize": true,
"lineHeight": 1.2857142857142858
},
{
"type": "rectangle",
"version": 910,
"versionNonce": 391148577,
"isDeleted": false,
"id": "STAkXjIBdAZgXMIKZfGnx",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 839.6978581986145,
"y": 387.38672884058093,
"strokeColor": "#9775fa",
"backgroundColor": "#9775fa",
"width": 121,
"height": 60.846153846153825,
"seed": 362222090,
"groupIds": [
"DlS9eiqyrIHp45FmS35GN"
],
"strokeSharpness": "sharp",
"boundElements": [
{
"type": "text",
"id": "1iyFs-1PG5afe6QKq1s34"
}
],
"updated": 1731149289560,
"index": "aC",
"frameId": null,
"roundness": null,
"link": null,
"locked": false
},
{
"type": "text",
"version": 690,
"versionNonce": 456727151,
"isDeleted": false,
"id": "1iyFs-1PG5afe6QKq1s34",
"fillStyle": "cross-hatch",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"angle": 0,
"x": 861.8895238480286,
"y": 399.80980576365783,
"strokeColor": "#1e1e1e",
"backgroundColor": "#03a9f4",
"width": 76.61666870117188,
"height": 36,
"seed": 565985482,
"groupIds": [
"DlS9eiqyrIHp45FmS35GN"
],
"strokeSharpness": "sharp",
"boundElements": [],
"updated": 1731149289560,
"fontSize": 28,
"fontFamily": 1,
"text": "Agent",
"baseline": 25,
"textAlign": "center",
"verticalAlign": "middle",
"containerId": "STAkXjIBdAZgXMIKZfGnx",
"originalText": "Agent",
"index": "aD",
"frameId": null,
"roundness": null,
"link": null,
"locked": false,
"autoResize": true,
"lineHeight": 1.2857142857142858
}
],
"appState": {
"gridSize": null,
"gridSize": 20,
"gridStep": 5,
"gridModeEnabled": false,
"viewBackgroundColor": "#ffffff"
},
"files": {}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB

After

Width:  |  Height:  |  Size: 437 KiB

+16 -8
View File
@@ -5,7 +5,7 @@
</p>
<p align="center">
<b>All-in-one embeddings database</b>
<b>All-in-one AI framework</b>
</p>
<p align="center">
@@ -18,7 +18,7 @@
<a href="https://github.com/neuml/txtai/issues">
<img src="https://img.shields.io/github/issues/neuml/txtai.svg?style=flat&color=success" alt="GitHub issues"/>
</a>
<a href="https://join.slack.com/t/txtai/shared_invite/zt-1cagya4yf-DQeuZbd~aMwH5pckBU4vPg">
<a href="https://join.slack.com/t/txtai/shared_invite/zt-37c1zfijp-Y57wMty6YOx_hyIHEQvQJA">
<img src="https://img.shields.io/badge/slack-join-blue?style=flat&logo=slack&logocolor=white" alt="Join Slack"/>
</a>
<a href="https://github.com/neuml/txtai/actions?query=workflow%3Abuild">
@@ -29,14 +29,16 @@
</a>
</p>
txtai is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.
txtai is an all-in-one AI framework for semantic search, LLM orchestration and language model workflows.
![architecture](images/architecture.png#gh-light-mode-only)
![architecture](images/architecture-dark.png#gh-dark-mode-only)
Embeddings databases are a union of vector indexes (sparse and dense), graph networks and relational databases. This enables vector search with SQL, topic modeling, retrieval augmented generation (RAG) and more.
The key component of txtai is an embeddings database, which is a union of vector indexes (sparse and dense), graph networks and relational databases.
Embeddings databases can stand on their own and/or serve as a powerful knowledge source for large language model (LLM) prompts.
This foundation enables vector search and/or serves as a powerful knowledge source for large language model (LLM) applications.
Build autonomous agents, retrieval augmented generation (RAG) processes, multi-model workflows and more.
Summary of txtai features:
@@ -44,9 +46,15 @@ Summary of txtai features:
- 📄 Create embeddings for text, documents, audio, images and video
- 💡 Pipelines powered by language models that run LLM prompts, question-answering, labeling, transcription, translation, summarization and more
- ↪️️ Workflows to join pipelines together and aggregate business logic. txtai processes can be simple microservices or multi-model workflows.
- ⚙️ Build with Python or YAML. API bindings available for [JavaScript](https://github.com/neuml/txtai.js), [Java](https://github.com/neuml/txtai.java), [Rust](https://github.com/neuml/txtai.rs) and [Go](https://github.com/neuml/txtai.go).
- 🤖 Agents that intelligently connect embeddings, pipelines, workflows and other agents together to autonomously solve complex problems
- ⚙️ Web and Model Context Protocol (MCP) APIs. Bindings available for [JavaScript](https://github.com/neuml/txtai.js), [Java](https://github.com/neuml/txtai.java), [Rust](https://github.com/neuml/txtai.rs) and [Go](https://github.com/neuml/txtai.go).
- 🔋 Batteries included with defaults to get up and running fast
- ☁️ Run local or scale out with container orchestration
txtai is built with Python 3.8+, [Hugging Face Transformers](https://github.com/huggingface/transformers), [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [FastAPI](https://github.com/tiangolo/fastapi). txtai is open-source under an Apache 2.0 license.
txtai is built with Python 3.11+, [Hugging Face Transformers](https://github.com/huggingface/transformers), [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [FastAPI](https://github.com/tiangolo/fastapi). txtai is open-source under an Apache 2.0 license.
*Interested in an easy and secure way to run hosted txtai applications? Then join the [txtai.cloud](https://txtai.cloud) preview to learn more.*
!!! note
[NeuML](https://neuml.com) is the company behind txtai and we provide AI consulting services around our stack. [Schedule a meeting](https://cal.com/neuml/intro) or [send a message](mailto:[email protected]) to learn more.
We're also building an easy and secure way to run hosted txtai applications with [txtai.cloud](https://txtai.cloud).
+27 -5
View File
@@ -9,7 +9,7 @@ The easiest way to install is via pip and PyPI
pip install txtai
```
Python 3.8+ is supported. Using a Python [virtual environment](https://docs.python.org/3/library/venv.html) is recommended.
Python 3.11+ is supported. Using a Python [virtual environment](https://docs.python.org/3/library/venv.html) is recommended.
## Optional dependencies
@@ -130,12 +130,18 @@ Additional environment specific prerequisites are below.
### Linux
Optional audio transcription requires a [system library to be installed](https://github.com/bastibe/python-soundfile#installation)
The AudioStream and Microphone pipelines require the [PortAudio](https://python-sounddevice.readthedocs.io/en/0.5.0/installation.html) system library.
The Transcription pipeline requires the [SoundFile](https://github.com/bastibe/python-soundfile#installation) system library.
The LiteRT LLM pipeline requires libegl1, libgles2 and libvulkan1.
### macOS
Older versions of Faiss have a runtime dependency on `libomp` for macOS. Run `brew install libomp` in this case.
The AudioStream and Microphone pipelines require the [PortAudio](https://python-sounddevice.readthedocs.io/en/0.5.0/installation.html) system library. Run `brew install portaudio`.
### Windows
Optional dependencies require [C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
@@ -144,14 +150,14 @@ The [txtai build workflow](https://github.com/neuml/txtai/blob/master/.github/wo
## CPU-only
The default install adds PyTorch with GPU support. There are a number of dependencies that come with that. When running in a CPU-only environment or using Embeddings/LLM models without PyTorch (i.e. llama.cpp or API services), the CPU-only PyTorch package can be installed with txtai as follows.
The default install adds PyTorch with GPU support. There are a number of dependencies that come with that. When running in a CPU-only environment, the CPU-only PyTorch package can be installed with txtai as follows.
```
pip install txtai torch==[version]+cpu \
-f https://download.pytorch.org/whl/torch_stable.html
-f https://download.pytorch.org/whl/torch
```
Where `[version]` is the version of PyTorch (such as 2.3.1). The [txtai-cpu](https://hub.docker.com/r/neuml/txtai-cpu) image on Docker Hub uses this method to reduce the image size.
Where `[version]` is the version of PyTorch (such as 2.4.1). The [txtai-cpu](https://hub.docker.com/r/neuml/txtai-cpu) image on Docker Hub uses this method to reduce the image size.
## Install from source
@@ -171,6 +177,22 @@ A [community-supported txtai package](https://anaconda.org/conda-forge/txtai) is
conda install -c conda-forge txtai
```
## Minimal install
A lightweight zero dependency minimal install package is available. This is helpful if the default libraries are too heavy or there are no plans to use them.
All the same extras mentioned above are available in this version of the package.
```
# Lightweight minimal install
pip install txtai_minimal
# Same as standard `txtai` install
pip install txtai_minimal[default]
```
Note that in order to use the `Embeddings` or `LLM` interface without `torch` requires either `llama.cpp`, `litellm` or `litert`.
## Run with containers
Docker images are available for txtai. [See this section](../cloud) for more information on container-based installs.
+4 -5
View File
@@ -8,9 +8,9 @@ See the table below for the current recommended models. These models all allow c
| ---------------------------------------------------- | ------------------------------------------------------------------------ |
| [Embeddings](../embeddings) | [all-MiniLM-L6-v2](https://hf.co/sentence-transformers/all-MiniLM-L6-v2) |
| [Image Captions](./pipeline/image/caption.md) | [BLIP](https://hf.co/Salesforce/blip-image-captioning-base) |
| [Labels - Zero Shot](./pipeline/text/labels.md) | [BART-Large-MNLI](https://hf.co/facebook/bart-large) |
| [Labels - Zero Shot](./pipeline/text/labels.md) | [DeBERTa v3 Zeroshot](https://hf.co/MoritzLaurer/deberta-v3-base-zeroshot-v2.0-c) |
| [Labels - Fixed](./pipeline/text/labels.md) | Fine-tune with [training pipeline](./pipeline/train/trainer.md) |
| [Large Language Model (LLM)](./pipeline/text/llm.md) | [Mistral 7B OpenOrca](https://hf.co/Open-Orca/Mistral-7B-OpenOrca) |
| [Large Language Model (LLM)](./pipeline/text/llm.md) | [Gemma 4 31B](https://hf.co/google/gemma-4-31B) |
| [Summarization](./pipeline/text/summary.md) | [DistilBART](https://hf.co/sshleifer/distilbart-cnn-12-6) |
| [Text-to-Speech](./pipeline/audio/texttospeech.md) | [ESPnet JETS](https://hf.co/NeuML/ljspeech-jets-onnx) |
| [Transcription](./pipeline/audio/transcription.md) | [Whisper](https://hf.co/openai/whisper-base) |
@@ -22,6 +22,5 @@ See the following links to learn more.
- [Hugging Face Tasks](https://hf.co/tasks)
- [Hugging Face Model Hub](https://hf.co/models)
- [MTEB Leaderboard](https://hf.co/spaces/mteb/leaderboard)
- [LMSYS LLM Leaderboard](https://chat.lmsys.org/?leaderboard)
- [Open LLM Leaderboard](https://hf.co/spaces/HuggingFaceH4/open_llm_leaderboard)
- [Embeddings Leaderboard](https://hf.co/spaces/mteb/leaderboard)
- [LLM Leaderboard](https://hf.co/spaces/lmarena-ai/arena-leaderboard)
+182
View File
@@ -0,0 +1,182 @@
# Observability
![agent](https://raw.githubusercontent.com/neuml/mlflow-txtai/master/images/agent.png)
Observability enables tracking the inner workings of a system without having to change the system. This makes it much easier to debug and evaluate overall performance.
`txtai` has an integration with [MLflow](https://mlflow.org) and it's [tracing module](https://mlflow.org/docs/latest/llms/tracing/index.html) to provide insights into each of the components in `txtai`.
## Examples
The following shows a number of examples on how to introduce observability into a `txtai` process.
### Initialization
Run the following sections first to initialize tracing.
```
# Install MLflow plugin for txtai
pip install mlflow-txtai
# Start a local MLflow service
mlflow server --host 127.0.0.1 --port 8000
```
```python
import mlflow
mlflow.set_tracking_uri(uri="http://localhost:8000")
mlflow.set_experiment("txtai")
# Enable txtai automatic tracing
mlflow.txtai.autolog()
```
### Textractor
The first example traces a [Textractor pipeline](../pipeline/data/textractor).
```python
from txtai.pipeline import Textractor
with mlflow.start_run():
textractor = Textractor()
textractor("https://github.com/neuml/txtai")
```
![textractor](https://raw.githubusercontent.com/neuml/mlflow-txtai/master/images/textractor.png)
### Embeddings
Next, we'll trace an [Embeddings](../embeddings) query.
```python
from txtai import Embeddings
with mlflow.start_run():
wiki = Embeddings()
wiki.load(provider="huggingface-hub", container="neuml/txtai-wikipedia-slim")
embeddings = Embeddings(content=True, graph=True)
embeddings.index(wiki.search("SELECT id, text FROM txtai LIMIT 25"))
embeddings.search("MATCH (A)-[]->(B) RETURN A")
```
![embeddings-load](https://raw.githubusercontent.com/neuml/mlflow-txtai/master/images/embeddings-load.png)
![embeddings-index](https://raw.githubusercontent.com/neuml/mlflow-txtai/master/images/embeddings-index.png)
### Retrieval Augmented Generation (RAG)
The next example traces a [RAG pipeline](../pipeline/text/rag).
```python
from txtai import Embeddings, RAG
with mlflow.start_run():
wiki = Embeddings()
wiki.load(provider="huggingface-hub", container="neuml/txtai-wikipedia-slim")
# Define prompt template
template = """
Answer the following question using only the context below. Only include information
specifically discussed.
question: {question}
context: {context} """
# Create RAG pipeline
rag = RAG(
wiki,
"openai/gpt-oss-20b",
system="You are a friendly assistant. You answer questions from users.",
template=template,
context=10
)
rag("Tell me about the Roman Empire", maxlength=2048)
```
![rag](https://raw.githubusercontent.com/neuml/mlflow-txtai/master/images/rag.png)
### Workflow
This example runs a [workflow](../workflow). This workflow runs an embeddings query and then translates each result to French.
```python
from txtai import Embeddings, Workflow
from txtai.pipeline import Translation
from txtai.workflow import Task
with mlflow.start_run():
wiki = Embeddings()
wiki.load(provider="huggingface-hub", container="neuml/txtai-wikipedia-slim")
# Translation instance
translate = Translation()
workflow = Workflow([
Task(lambda x: [y[0]["text"] for y in wiki.batchsearch(x, 1)]),
Task(lambda x: translate(x, "fr"))
])
print(list(workflow(["Roman Empire", "Greek Empire", "Industrial Revolution"])))
```
![workflow](https://raw.githubusercontent.com/neuml/mlflow-txtai/master/images/workflow.png)
### Agent
The last example runs a [txtai agent](../agent) designed to research questions on astronomy.
```python
from txtai import Agent, Embeddings
def search(query):
"""
Searches a database of astronomy data.
Make sure to call this tool only with a string input, never use JSON.
Args:
query: concepts to search for using similarity search
Returns:
list of search results with for each match
"""
return embeddings.search(
"SELECT id, text, distance FROM txtai WHERE similar(:query)",
10, parameters={"query": query}
)
embeddings = Embeddings()
embeddings.load(provider="huggingface-hub", container="neuml/txtai-astronomy")
agent = Agent(
tools=[search],
llm="Qwen/Qwen3-4B-Instruct-2507",
max_steps=10,
)
researcher = """
{command}
Do the following.
- Search for results related to the topic.
- Analyze the results
- Continue querying until conclusive answers are found
- Write a Markdown report
"""
with mlflow.start_run():
agent(researcher.format(command="""
Write a detailed list with explanations of 10 candidate stars that could potentially be habitable to life.
"""), maxlength=16000)
```
![agent](https://raw.githubusercontent.com/neuml/mlflow-txtai/master/images/agent.png)
## Read more
Check out the [mlflow-txtai](https://github.com/neuml/mlflow-txtai) project to see more examples.
+68
View File
@@ -0,0 +1,68 @@
# Audio Mixer
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The Audio Mixer pipeline mixes multiple audio streams into a single stream.
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import AudioMixer
# Create and run pipeline
mixer = AudioMixer()
mixer(((audio1, rate1), (audio2, rate2)))
```
See the link below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Generative Audio](https://github.com/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) | Storytelling with generative audio workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) |
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
audiomixer:
# Run pipeline with workflow
workflow:
audiomixer:
tasks:
- action: audiomixer
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("audiomixer", [[[audio1, rate1], [audio2, rate2]]]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"audiomixer", "elements":[[[audio1, rate1], [audio2, rate2]]]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.AudioMixer.__init__
### ::: txtai.pipeline.AudioMixer.__call__
+70
View File
@@ -0,0 +1,70 @@
# Audio Stream
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The Audio Stream pipeline is a threaded pipeline that plays audio segments. This pipeline is designed to run on local machines given that it requires access to write to an output device.
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import AudioStream
# Create and run pipeline
audio = AudioStream()
audio(data)
```
This pipeline may require additional system dependencies. See [this section](../../../install#environment-specific-prerequisites) for more.
See the link below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
audiostream:
# Run pipeline with workflow
workflow:
audiostream:
tasks:
- action: audiostream
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("audiostream", [["numpy data", "sample rate"]]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"audiostream", "elements":[["numpy data", "sample rate"]]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.AudioStream.__init__
### ::: txtai.pipeline.AudioStream.__call__
+70
View File
@@ -0,0 +1,70 @@
# Microphone
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The Microphone pipeline reads input speech from a microphone device. This pipeline is designed to run on local machines given that it requires access to read from an input device.
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import Microphone
# Create and run pipeline
microphone = Microphone()
microphone()
```
This pipeline may require additional system dependencies. See [this section](../../../install#environment-specific-prerequisites) for more.
See the link below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
microphone:
# Run pipeline with workflow
workflow:
microphone:
tasks:
- action: microphone
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("microphone", ["1"]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"microphone", "elements":["1"]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.Microphone.__init__
### ::: txtai.pipeline.Microphone.__call__
+68
View File
@@ -0,0 +1,68 @@
# Text To Audio
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The Text To Audio pipeline generates audio from text.
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import TextToAudio
# Create and run pipeline
tta = TextToAudio()
tta("Describe the audio to generate here")
```
See the link below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Generative Audio](https://github.com/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) | Storytelling with generative audio workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) |
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
texttoaudio:
# Run pipeline with workflow
workflow:
tta:
tasks:
- action: texttoaudio
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("tta", ["Describe the audio to generate here"]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"tta", "elements":["Describe the audio to generate here"]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.TextToAudio.__init__
### ::: txtai.pipeline.TextToAudio.__call__
+21 -2
View File
@@ -12,21 +12,40 @@ The following shows a simple example using this pipeline.
```python
from txtai.pipeline import TextToSpeech
# Create and run pipeline
# Create and run pipeline with default model
tts = TextToSpeech()
tts("Say something here")
# Stream audio - incrementally generates snippets of audio
yield from tts(
"Say something here. And say something else.".split(),
stream=True
)
# Generate audio using a speaker id
tts = TextToSpeech("neuml/vctk-vits-onnx")
tts("Say something here", speaker=15)
# Generate audio using speaker embeddings
tts = TextToSpeech("neuml/txtai-speecht5-onnx")
tts("Say something here", speaker=np.array(...))
```
See the link below for a more detailed example.
See the links below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Text to speech generation](https://github.com/neuml/txtai/blob/master/examples/40_Text_to_Speech_Generation.ipynb) | Generate speech from text | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/40_Text_to_Speech_Generation.ipynb) |
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
| [Generative Audio](https://github.com/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) | Storytelling with generative audio workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/66_Generative_Audio.ipynb) |
This pipeline is backed by ONNX models from the Hugging Face Hub. The following models are currently available.
- [kokoro-base-onnx](https://huggingface.co/NeuML/kokoro-base-onnx) | [fp16](https://huggingface.co/NeuML/kokoro-fp16-onnx) | [int8](https://huggingface.co/NeuML/kokoro-int8-onnx)
- [ljspeech-jets-onnx](https://huggingface.co/NeuML/ljspeech-jets-onnx)
- [ljspeech-vits-onnx](https://huggingface.co/NeuML/ljspeech-vits-onnx)
- [vctk-vits-onnx](https://huggingface.co/NeuML/vctk-vits-onnx)
- [txtai-speecht5-onnx](https://huggingface.co/NeuML/txtai-speecht5-onnx)
## Configuration-driven example
+4 -1
View File
@@ -17,11 +17,14 @@ transcribe = Transcription()
transcribe("path to wav file")
```
See the link below for a more detailed example.
This pipeline may require additional system dependencies. See [this section](../../../install#environment-specific-prerequisites) for more.
See the links below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Transcribe audio to text](https://github.com/neuml/txtai/blob/master/examples/11_Transcribe_audio_to_text.ipynb) | Convert audio files to text | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/11_Transcribe_audio_to_text.ipynb) |
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
## Configuration-driven example
+80
View File
@@ -0,0 +1,80 @@
# File To HTML
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The File To HTML pipeline transforms files to HTML. It supports the following text extraction backends.
## Apache Tika
[Apache Tika](https://tika.apache.org/) detects and extracts metadata and text from over a thousand different file types. See [this link](https://tika.apache.org/2.9.2/formats.html) for a list of supported document formats.
Apache Tika requires [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) to be installed. An alternative to that is starting a separate Apache Tika service via [this Docker Image](https://hub.docker.com/r/apache/tika) and setting these [environment variables](https://github.com/chrismattmann/tika-python?tab=readme-ov-file#environment-variables).
## Docling
[Docling](https://github.com/DS4SD/docling) parses documents and exports them to the desired format with ease and speed. This is a library that has rapidly gained popularity starting in late 2024. Docling excels in parsing formatting elements from PDFs (tables, sections etc).
See [this link](https://github.com/DS4SD/docling?tab=readme-ov-file#features) for a list of supported document formats.
## LiteParse
[LiteParse](https://github.com/run-llama/liteparse) is a fast, helpful, and open-source document parser. It supports PDF out of the box with additional format support via third-party packages.
See [this link](https://github.com/run-llama/liteparse#multi-format-input-support) for more.
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import FileToHTML
# Create and run pipeline
html = FileToHTML()
html("/path/to/file")
```
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
filetohtml:
# Run pipeline with workflow
workflow:
html:
tasks:
- action: filetohtml
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("html", ["/path/to/file"]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"html", "elements":["/path/to/file"]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.FileToHTML.__init__
### ::: txtai.pipeline.FileToHTML.__call__
+68
View File
@@ -0,0 +1,68 @@
# HTML To Markdown
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The HTML To Markdown pipeline transforms HTML to Markdown.
Markdown formatting is applied for headings, blockquotes, lists, code, tables and text. Visual formatting is also included (bold, italic etc).
This pipeline searches for the best node that has relevant text, often found with an `article`, `main` or `body` tag.
The HTML to Markdown pipeline requires the [BeautifulSoup4](https://pypi.org/project/beautifulsoup4/) library to be installed.
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import HTMLToMarkdown
# Create and run pipeline
md = HTMLToMarkdown()
md("<html><body>This is a test</body></html>")
```
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
htmltomarkdown:
# Run pipeline with workflow
workflow:
markdown:
tasks:
- action: htmltomarkdown
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("markdown", ["<html><body>This is a test</body></html>"]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"markdown", "elements":["<html><body>This is a test</body></html>"]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.HTMLToMarkdown.__init__
### ::: txtai.pipeline.HTMLToMarkdown.__call__
+6
View File
@@ -15,8 +15,14 @@ from txtai.pipeline import Segmentation
# Create and run pipeline
segment = Segmentation(sentences=True)
segment("This is a test. And another test.")
# Load third-party chunkers
segment = Segmentation(chunker="semantic")
segment("This is a test. And another test.")
```
The Segmentation pipeline supports segmenting `sentences`, `lines`, `paragraphs` and `sections` using a rules-based approach. Each of these modes can be set when creating the pipeline. Third-party chunkers are also supported via the `chunker` parameter.
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
+10 -4
View File
@@ -3,15 +3,20 @@
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The Textractor pipeline extracts and splits text from documents. This pipeline uses [Apache Tika](https://github.com/chrismattmann/tika-python) (if Java is available) and [BeautifulSoup4](https://pypi.org/project/beautifulsoup4/). See [this link](https://tika.apache.org/2.9.2/formats.html) for a list of supported document formats.
The Textractor pipeline extracts and splits text from documents. This pipeline extends the [Segmentation](../segmentation) pipeline.
Each document goes through the following process.
- Content is retrieved if it's not local
- If the document `mime-type` isn't plain text or HTML, it's run through Tika and converted to XHTML
- XHTML is converted to Markdown and returned
- If the document `mime-type` isn't plain text or HTML, it's converted to HTML via the [FiletoHTML](../filetohtml) pipeline
- HTML is converted to Markdown via the [HTMLToMarkdown](../htmltomd) pipeline
- Content is split/chunked based on the [segmentation parameters](../segmentation/#txtai.pipeline.Segmentation.__init__) and returned
Without Apache Tika, this pipeline only supports plain text and HTML. Other document types require Tika and Java to be installed. Another option is to start Apache Tika via [this Docker Image](https://hub.docker.com/r/apache/tika).
The [backend](../filetohtml/#txtai.pipeline.FileToHTML.__init__) parameter sets the FileToHTML pipeline backend. If a backend isn't available, this pipeline assumes input is HTML content and only converts it to Markdown.
See the [FiletoHTML](../filetohtml) and [HTMLToMarkdown](../htmltomd) pipelines to learn more on the dependencies necessary for each of those pipelines.
Note that the default parameters enable access to all local files and all URLs. The `safeopen` parameter limits this to only files in a specified directory (defaults to temp directory) and public URLs. When running the textractor pipeline through an Application or via the API, `safeopen` defaults to True. It can be disabled if desired via configuration.
## Example
@@ -30,6 +35,7 @@ See the link below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Extract text from documents](https://github.com/neuml/txtai/blob/master/examples/10_Extract_text_from_documents.ipynb) | Extract text from PDF, Office, HTML and more | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/10_Extract_text_from_documents.ipynb) |
| [Chunking your data for RAG](https://github.com/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) | Extract, chunk and index content for effective retrieval | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) |
## Configuration-driven example
+82
View File
@@ -0,0 +1,82 @@
# Tokenizer
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The Tokenizer pipeline splits text into tokens. This is primarily used for keyword / term indexing.
_Note: Transformers-based models have their own tokenizers and this pipeline isn't designed for working with Transformers models._
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import Tokenizer
# Create and run pipeline
tokenizer = Tokenizer()
tokenizer("text to tokenize")
# Whitespace tokenization
tokenizer = Tokenizer(whitespace=True)
tokenizer("text to tokenize")
# Tokenize using a regular expression
tokenizer = Tokenizer(regexp=r"\w{5,}")
tokenizer("text to tokenize")
# Tokenize into trigrams like pg_trgm
tokenizer = Tokenizer(ngrams={
"ngrams": 3, "lpad": " ", "rpad": " ", "unique": True
})
tokenize("text to tokenize")
# Tokenize into edge ngrams
tokenizer = Tokenizer(ngrams={"nmin": 2, "nmax": 5, "edge": True})
tokenizer("text to tokenize")
```
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
tokenizer:
# Run pipeline with workflow
workflow:
tokenizer:
tasks:
- action: tokenizer
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("tokenizer", ["text to tokenize"]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"tokenizer", "elements":["text"]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.Tokenizer.__init__
### ::: txtai.pipeline.Tokenizer.__call__
+62
View File
@@ -0,0 +1,62 @@
# URL Retrieve
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The URL Retrieve pipeline retrieves content from a HTTP(s) URL.
## Example
The following shows a simple example using this pipeline.
```python
from txtai.pipeline import URLRetrieve
# Create and run pipeline
urlretrieve = URLRetrieve()
urlretrieve("https://github.com/neuml/txtai")
```
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
urlretrieve:
# Run pipeline with workflow
workflow:
retrieve:
tasks:
- action: urlretrieve
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("urlretrieve", ["https://github.com/neuml/txtai"]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"retrieve", "elements":["http://github.com/neuml/txtai"]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.URLRetrieve.__init__
### ::: txtai.pipeline.URLRetrieve.__call__
+12 -1
View File
@@ -9,15 +9,25 @@ Pipelines are run with Python or configuration. Pipelines can be instantiated in
## List of pipelines
The following is a list of the default pipelines available in txtai. All pipelines use default models when otherwise not specified. See the [model guide](../models) for the current model recommentations.
The following is a list of the current pipelines available in txtai. All pipelines use default models when otherwise not specified. See the [model guide](../models) for the current model recommendations. All pipelines are designed to work with local models via the [Transformers library](https://github.com/huggingface/transformers).
The `LLM` and `RAG` pipelines also have integrations for [llama.cpp](https://github.com/abetlen/llama-cpp-python) and [hosted API models via LiteLLM](https://github.com/BerriAI/litellm). The `LLM` pipeline can be prompted to accomplish many of the same tasks (i.e. summarization, translation, classification).
- Audio
- [AudioMixer](audio/audiomixer)
- [AudioStream](audio/audiostream)
- [Microphone](audio/microphone)
- [TextToAudio](audio/texttoaudio)
- [TextToSpeech](audio/texttospeech)
- [Transcription](audio/transcription)
- Data Processing
- [FileToHTML](data/filetohtml)
- [HTMLToMarkdown](data/htmltomd)
- [Segmentation](data/segmentation)
- [Tabular](data/tabular)
- [Text extraction](data/textractor)
- [Tokenizer](data/tokenizer)
- [URLRetrieve](data/urlretrieve)
- Image
- [Caption](image/caption)
- [Image Hash](image/imagehash)
@@ -27,6 +37,7 @@ The following is a list of the default pipelines available in txtai. All pipelin
- [Labeling](text/labels)
- [LLM](text/llm)
- [RAG](text/rag)
- [Reranker](text/reranker)
- [Similarity](text/similarity)
- [Summary](text/summary)
- [Translation](text/translation)
+225
View File
@@ -0,0 +1,225 @@
# LLM
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The LLM pipeline runs prompts through a large language model (LLM). This pipeline autodetects the LLM framework based on the model path.
## Example
The following shows a simple example using this pipeline.
```python
from txtai import LLM
# Create LLM pipeline
llm = LLM()
# Run prompt
llm(
"""
Answer the following question using the provided context.
Question:
What are the applications of txtai?
Context:
txtai is an open-source platform for semantic search and
workflows powered by language models.
"""
)
# Prompts with chat templating can be directly passed
# The template format varies by model
llm(
"""
<|im_start|>system
You are a friendly assistant.<|im_end|>
<|im_start|>user
Answer the following question...<|im_end|>
<|im_start|>assistant
"""
)
# Chat messages automatically handle templating
llm([
{"role": "system", "content": "You are a friendly assistant."},
{"role": "user", "content": "Answer the following question..."}
])
# When there is no system prompt passed to instruction tuned models
# the default role is inferred `defaultrole="auto"`
llm("Answer the following question...")
# To always generate chat messages for string inputs
llm("Answer the following question...", defaultrole="user")
# To never generate chat messages for string inputs
llm("Answer the following question...", defaultrole="prompt")
```
The LLM pipeline automatically detects the underlying LLM framework. This can also be manually set. The following methods are supported.
- [Hugging Face Transformers](https://github.com/huggingface/transformers)
- [llama.cpp](https://github.com/abetlen/llama-cpp-python)
- [LLM APIs via LiteLLM](https://github.com/BerriAI/litellm)
- [LiteRT-LM](https://ai.google.dev/edge/litert-lm)
- [OpenCode server](https://github.com/anomalyco/opencode)
`llama.cpp` and `LiteRT-LM` support both local and remote file paths on the HF Hub.
See the [LiteLLM documentation](https://litellm.vercel.app/docs/providers) for the options available with LiteLLM models.
See the [OpenCode documentation](https://opencode.ai/docs/server/) for more on how to integrate the LLM pipeline with a running OpenCode instance.
```python
from txtai import LLM
# Transformers
llm = LLM("openai/gpt-oss-20b")
llm = LLM("openai/gpt-oss-20b", method="transformers")
# llama.cpp
llm = LLM("unsloth/gpt-oss-20b-GGUF/gpt-oss-20b-Q4_K_M.gguf")
llm = LLM("unsloth/gpt-oss-20b-GGUF/gpt-oss-20b-Q4_K_M.gguf",
method="llama.cpp")
# LiteLLM
llm = LLM("ollama/gpt-oss")
llm = LLM("ollama/gpt-oss", method="litellm")
# LiteRT-LM
llm = LLM(
"litert-community/gemma-4-E2B-it-litert-lm/gemma-4-E2B-it.litertlm"
)
llm = LLM(
"litert-community/gemma-4-E2B-it-litert-lm/gemma-4-E2B-it.litertlm",
method="litert"
)
# Custom Ollama endpoint
llm = LLM("ollama/gpt-oss", api_base="http://localhost:11434")
# Custom OpenAI-compatible endpoint
llm = LLM("openai/gpt-oss", api_base="http://localhost:4000")
# LLM APIs - must also set API key via environment variable
llm = LLM("gpt-5.2")
llm = LLM("claude-opus-4-5-20251101")
llm = LLM("gemini/gemini-3-pro-preview")
# Local OpenCode server started via `opencode serve`
llm = LLM("opencode")
llm = LLM("opencode/big-pickle", url="http://localhost:4000")
```
Models can be externally loaded and passed to pipelines. This is useful for models that are not yet supported by Transformers and/or need special initialization.
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from txtai import LLM
# Load Qwen3 0.6B
path = "Qwen/Qwen3-0.6B"
model = AutoModelForCausalLM.from_pretrained(
path,
dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(path)
llm = LLM((model, tokenizer))
```
See the links below for more detailed examples.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Prompt-driven search with LLMs](https://github.com/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) | Embeddings-guided and Prompt-driven search with Large Language Models (LLMs) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) |
| [Prompt templates and task chains](https://github.com/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) | Build model prompts and connect tasks together with workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) [▶️](https://www.youtube.com/watch?v=t_OeAc8NVfQ) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [Integrate LLM frameworks](https://github.com/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) | Integrate llama.cpp, LiteLLM and custom generation frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) |
| [Generate knowledge with Semantic Graphs and RAG](https://github.com/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) | Knowledge exploration and discovery with Semantic Graphs and RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) |
| [Build knowledge graphs with LLMs](https://github.com/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) | Build knowledge graphs with LLM-driven entity extraction | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) |
| [Advanced RAG with graph path traversal](https://github.com/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) | Graph path traversal to collect complex sets of data for advanced RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) |
| [Advanced RAG with guided generation](https://github.com/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) | Retrieval Augmented and Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) |
| [RAG with llama.cpp and external API services](https://github.com/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) | RAG with additional vector and LLM frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) |
| [How RAG with txtai works](https://github.com/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) | Create RAG processes, API services and Docker instances | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) |
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
| [Analyzing Hugging Face Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) | Explore a rich dataset with Graph Analysis and Agents | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/68_Analyzing_Hugging_Face_Posts_with_Graphs_and_Agents.ipynb) |
| [Granting autonomy to agents](https://github.com/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) | Agents that iteratively solve problems as they see fit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) |
| [Getting started with LLM APIs](https://github.com/neuml/txtai/blob/master/examples/70_Getting_started_with_LLM_APIs.ipynb) | Generate embeddings and run LLMs with OpenAI, Claude, Gemini, Bedrock and more | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/70_Getting_started_with_LLM_APIs.ipynb) |
| [Analyzing LinkedIn Company Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) | Exploring how to improve social media engagement with AI | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) |
| [Parsing the stars with txtai](https://github.com/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) | Explore an astronomical knowledge graph of known stars, planets, galaxies | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) |
| [Chunking your data for RAG](https://github.com/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) | Extract, chunk and index content for effective retrieval | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) |
| [Medical RAG Research with txtai](https://github.com/neuml/txtai/blob/master/examples/75_Medical_RAG_Research_with_txtai.ipynb) | Analyze PubMed article metadata with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/75_Medical_RAG_Research_with_txtai.ipynb) |
| [GraphRAG with Wikipedia and GPT OSS](https://github.com/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) | Deep graph search powered RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) |
| [RAG is more than Vector Search](https://github.com/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) | Context retrieval via Web, SQL and other sources | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) |
| [OpenCode as a txtai LLM](https://github.com/neuml/txtai/blob/master/examples/81_OpenCode_as_a_txtai_LLM.ipynb) | Integrate OpenCode with the txtai ecosystem | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/81_OpenCode_as_a_txtai_LLM.ipynb) |
| [Agentic College Search](https://github.com/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) | Identify a list of strong engineering colleges | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/82_Agentic_College_Search.ipynb) |
| [TxtAI got skills](https://github.com/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) | Integrate skill.md files with your agent | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) |
| [Agent Tools](https://github.com/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) [▶️](https://www.youtube.com/watch?v=RDNaFXQy3GQ) | Learn about the txtai agent toolkit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) |
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
llm:
# Run pipeline with workflow
workflow:
llm:
tasks:
- action: llm
```
Similar to the Python example above, the underlying [Hugging Face pipeline parameters](https://huggingface.co/docs/transformers/main/main_classes/pipelines#transformers.pipeline.model) and [model parameters](https://huggingface.co/docs/transformers/model_doc/auto#transformers.AutoModel.from_pretrained) can be set in pipeline configuration.
```yaml
llm:
path: Qwen/Qwen3-0.6B
dtype: torch.bfloat16
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("llm", [
"""
Answer the following question using the provided context.
Question:
What are the applications of txtai?
Context:
txtai is an open-source platform for semantic search and
workflows powered by language models.
"""
]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"llm", "elements": ["Answer the following question..."]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.LLM.__init__
### ::: txtai.pipeline.LLM.__call__
@@ -3,9 +3,9 @@
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The RAG pipeline (aka Extractor) joins a prompt, context data store and generative model together to extract knowledge.
The Retrieval Augmented Generation (RAG) pipeline joins a prompt, context data store and generative model together to extract knowledge.
The data store can be an embeddings database or a similarity instance with associated input text. The generative model can be a prompt-driven large language model (LLM), an extractive question-answering model or a custom pipeline. This is known as retrieval augmented generation (RAG).
The data store can be an embeddings database or a similarity instance with associated input text. The generative model can be a prompt-driven large language model (LLM), an extractive question-answering model or a custom pipeline.
## Example
@@ -27,11 +27,11 @@ data = [
]
# Build embeddings index
embeddings = Embeddings({"content": True})
embeddings = Embeddings(content=True)
embeddings.index(data)
# Create and run pipeline
rag = RAG(embeddings, "google/flan-t5-base", template="""
# Create the RAG pipeline
rag = RAG(embeddings, "Qwen/Qwen3-0.6B", template="""
Answer the following question using the provided context.
Question:
@@ -41,26 +41,71 @@ rag = RAG(embeddings, "google/flan-t5-base", template="""
{context}
""")
# Run RAG pipeline
rag("What was won?")
# Prompts with chat templating can be directly passed
# The template format varies by model
rag = RAG(embeddings, "Qwen/Qwen3-0.6B", template="""
<|im_start|>system
You are a friendly assistant.<|im_end|>
<|im_start|>user
Answer the following question using the provided context.
Question:
{question}
Context:
{context}
<|im_start|>assistant
"""
)
rag("What was won?")
# Inputs are automatically converted to chat messages when a
# system prompt is provided
rag = RAG(
embeddings,
"openai/gpt-oss-20b",
system="You are a friendly assistant",
template="""
Answer the following question using the provided context.
Question:
{question}
Context:
{context}
""")
rag("What was won?")
# LLM options can be passed as additional arguments
# - Streaming RAG response with `stream=True`
# - String inputs are always converted to user messages with `defaultrole="user"`
# - Thinking text is removed with `stripthink=True`
rag("What was won?", stream=True, defaultrole="user", stripThink=True)
```
See the links below for more detailed examples.
See the [Embeddings](../../../embeddings) and [LLM](../llm) pages for additional configuration options.
Check out this [RAG Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/rag_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Prompt-driven search with LLMs](https://github.com/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) | Embeddings-guided and Prompt-driven search with Large Language Models (LLMs) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) |
| [Prompt templates and task chains](https://github.com/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) | Build model prompts and connect tasks together with workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) [▶️](https://www.youtube.com/watch?v=t_OeAc8NVfQ) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [Integrate LLM frameworks](https://github.com/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) | Integrate llama.cpp, LiteLLM and custom generation frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) |
| [Generate knowledge with Semantic Graphs and RAG](https://github.com/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) | Knowledge exploration and discovery with Semantic Graphs and RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) |
| [Build knowledge graphs with LLMs](https://github.com/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) | Build knowledge graphs with LLM-driven entity extraction | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) |
| [Advanced RAG with graph path traversal](https://github.com/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) | Graph path traversal to collect complex sets of data for advanced RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) |
| [Advanced RAG with guided generation](https://github.com/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) | Retrieval Augmented and Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) |
| [RAG with llama.cpp and external API services](https://github.com/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) | RAG with additional vector and LLM frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) |
| [How RAG with txtai works](https://github.com/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) | Create RAG processes, API services and Docker instances | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) |
| [Extractive QA with txtai](https://github.com/neuml/txtai/blob/master/examples/05_Extractive_QA_with_txtai.ipynb) | Introduction to extractive question-answering with txtai | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/05_Extractive_QA_with_txtai.ipynb) |
| [Extractive QA with Elasticsearch](https://github.com/neuml/txtai/blob/master/examples/06_Extractive_QA_with_Elasticsearch.ipynb) | Run extractive question-answering queries with Elasticsearch | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/06_Extractive_QA_with_Elasticsearch.ipynb) |
| [Extractive QA to build structured data](https://github.com/neuml/txtai/blob/master/examples/20_Extractive_QA_to_build_structured_data.ipynb) | Build structured datasets using extractive question-answering | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/20_Extractive_QA_to_build_structured_data.ipynb) |
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
| [Parsing the stars with txtai](https://github.com/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) | Explore an astronomical knowledge graph of known stars, planets, galaxies | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) |
| [Chunking your data for RAG](https://github.com/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) | Extract, chunk and index content for effective retrieval | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/73_Chunking_your_data_for_RAG.ipynb) |
| [Medical RAG Research with txtai](https://github.com/neuml/txtai/blob/master/examples/75_Medical_RAG_Research_with_txtai.ipynb) | Analyze PubMed article metadata with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/75_Medical_RAG_Research_with_txtai.ipynb) |
| [GraphRAG with Wikipedia and GPT OSS](https://github.com/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) | Deep graph search powered RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) |
| [RAG is more than Vector Search](https://github.com/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) | Context retrieval via Web, SQL and other sources | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) |
## Configuration-driven example
@@ -76,7 +121,7 @@ embeddings:
content: True
rag:
path: google/flan-t5-base
path: Qwen/Qwen3-0.6B
template: |
Answer the following question using the provided context.
+6
View File
@@ -16,6 +16,11 @@ from txtai.pipeline import Entity
entity = Entity()
entity("Canada's last fully intact ice shelf has suddenly collapsed, " \
"forming a Manhattan-sized iceberg")
# Extract entities using a GLiNER model which supports dynamic labels
entity = Entity("gliner-community/gliner_medium-v2.5")
entity("Canada's last fully intact ice shelf has suddenly collapsed, " \
"forming a Manhattan-sized iceberg", labels=["country", "city"])
```
See the link below for a more detailed example.
@@ -23,6 +28,7 @@ See the link below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Entity extraction workflows](https://github.com/neuml/txtai/blob/master/examples/26_Entity_extraction_workflows.ipynb) | Identify entity/label combinations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/26_Entity_extraction_workflows.ipynb) |
| [Parsing the stars with txtai](https://github.com/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) | Explore an astronomical knowledge graph of known stars, planets, galaxies | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/72_Parsing_the_stars_with_txtai.ipynb) |
## Configuration-driven example
-160
View File
@@ -1,160 +0,0 @@
# LLM
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The LLM pipeline runs prompts through a large language model (LLM). This pipeline autodetects the LLM framework based on the model path.
## Example
The following shows a simple example using this pipeline.
```python
from txtai import LLM
# Create LLM pipeline
llm = LLM()
# Run prompt
llm(
"""
Answer the following question using the provided context.
Question:
What are the applications of txtai?
Context:
txtai is an open-source platform for semantic search and
workflows powered by language models.
"""
)
# Chat messages are also supported
llm([
{"role": "system", "content": "You are a friendly assistant."},
{"role": "user", "content": "Answer the following question..."}
])
```
The LLM pipeline automatically detects the underlying LLM framework. This can also be manually set.
See the [LiteLLM documentation](https://litellm.vercel.app/docs/providers) for the options available with LiteLLM models. llama.cpp models support both local and remote GGUF paths on the HF Hub.
```python
from txtai import LLM
# Transformers
llm = LLM("google/gemma-2-9b")
llm = LLM("google/gemma-2-9b", method="transformers")
# llama.cpp
llm = LLM("microsoft/Phi-3-mini-4k-instruct-gguf/Phi-3-mini-4k-instruct-gguf")
llm = LLM("microsoft/Phi-3-mini-4k-instruct-gguf/Phi-3-mini-4k-instruct-gguf",
method="llama.cpp")
# LiteLLM
llm = LLM("ollama/llama3")
llm = LLM("ollama/llama3", method="litellm")
# LLM APIs - must also set API key via environment variable
llm = LLM("gpt-4o")
llm = LLM("claude-3-5-sonnet-20240620")
```
Models can be externally loaded and passed to pipelines. This is useful for models that are not yet supported by Transformers and/or need special initialization.
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from txtai import LLM
# Load Mistral-7B-OpenOrca
path = "Open-Orca/Mistral-7B-OpenOrca"
model = AutoModelForCausalLM.from_pretrained(
path,
torch_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(path)
llm = LLM((model, tokenizer))
```
See the links below for more detailed examples.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Prompt-driven search with LLMs](https://github.com/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) | Embeddings-guided and Prompt-driven search with Large Language Models (LLMs) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/42_Prompt_driven_search_with_LLMs.ipynb) |
| [Prompt templates and task chains](https://github.com/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) | Build model prompts and connect tasks together with workflows | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/44_Prompt_templates_and_task_chains.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [Integrate LLM frameworks](https://github.com/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) | Integrate llama.cpp, LiteLLM and custom generation frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) |
| [Generate knowledge with Semantic Graphs and RAG](https://github.com/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) | Knowledge exploration and discovery with Semantic Graphs and RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/55_Generate_knowledge_with_Semantic_Graphs_and_RAG.ipynb) |
| [Build knowledge graphs with LLMs](https://github.com/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) | Build knowledge graphs with LLM-driven entity extraction | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) |
| [Advanced RAG with graph path traversal](https://github.com/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) | Graph path traversal to collect complex sets of data for advanced RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) |
| [Advanced RAG with guided generation](https://github.com/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) | Retrieval Augmented and Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) |
| [RAG with llama.cpp and external API services](https://github.com/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) | RAG with additional vector and LLM frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/62_RAG_with_llama_cpp_and_external_API_services.ipynb) |
| [How RAG with txtai works](https://github.com/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) | Create RAG processes, API services and Docker instances | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) |
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
# Create pipeline using lower case class name
llm:
# Run pipeline with workflow
workflow:
llm:
tasks:
- action: llm
```
Similar to the Python example above, the underlying [Hugging Face pipeline parameters](https://huggingface.co/docs/transformers/main/main_classes/pipelines#transformers.pipeline.model) and [model parameters](https://huggingface.co/docs/transformers/model_doc/auto#transformers.AutoModel.from_pretrained) can be set in pipeline configuration.
```yaml
llm:
path: Open-Orca/Mistral-7B-OpenOrca
torch_dtype: torch.bfloat16
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("llm", [
"""
Answer the following question using the provided context.
Question:
What are the applications of txtai?
Context:
txtai is an open-source platform for semantic search and
workflows powered by language models.
"""
]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"llm", "elements": ["Answer the following question..."]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.LLM.__init__
### ::: txtai.pipeline.LLM.__call__
+82
View File
@@ -0,0 +1,82 @@
# Reranker
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
The Reranker pipeline runs embeddings queries and re-ranks them using a similarity pipeline.
## Example
The following shows a simple example using this pipeline.
```python
from txtai import Embeddings
from txtai.pipeline import Reranker, Similarity
# Embeddings instance
embeddings = Embeddings()
embeddings.load(provider="huggingface-hub", container="neuml/txtai-wikipedia")
# Similarity instance
similarity = Similarity(path="colbert-ir/colbertv2.0", lateencode=True)
# Reranking pipeline
reranker = Reranker(embeddings, similarity)
reranker("Tell me about AI")
```
_Note: Content must be enabled with the embeddings instance for this to work properly._
See the link below for a more detailed example.
| Notebook | Description | |
|:----------|:-------------|------:|
| [What's new in txtai 9.0](https://github.com/neuml/txtai/blob/master/examples/76_Whats_new_in_txtai_9_0.ipynb) | Learned sparse vectors, late interaction models and rerankers | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/76_Whats_new_in_txtai_9_0.ipynb) |
## Configuration-driven example
Pipelines are run with Python or configuration. Pipelines can be instantiated in [configuration](../../../api/configuration/#pipeline) using the lower case name of the pipeline. Configuration-driven pipelines are run with [workflows](../../../workflow/#configuration-driven-example) or the [API](../../../api#local-instance).
### config.yml
```yaml
embeddings:
similarity:
# Create pipeline using lower case class name
reranker:
# Run pipeline with workflow
workflow:
translate:
tasks:
- reranker
```
### Run with Workflows
```python
from txtai import Application
# Create and run pipeline with workflow
app = Application("config.yml")
list(app.workflow("reranker", ["Tell me about AI"]))
```
### Run with API
```bash
CONFIG=config.yml uvicorn "txtai.api:app" &
curl \
-X POST "http://localhost:8000/workflow" \
-H "Content-Type: application/json" \
-d '{"name":"rerank", "elements":["Tell me about AI"]}'
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.Reranker.__init__
### ::: txtai.pipeline.Reranker.__call__
+1 -1
View File
@@ -7,7 +7,7 @@ The Similarity pipeline computes similarity between queries and list of text usi
This pipeline supports both standard text classification models and zero-shot classification models. The pipeline uses the queries as labels for the input text. The results are transposed to get scores per query/label vs scores per input text.
Cross-encoder models are supported via the `crossencode=True` constructor parameter. These models are loaded with a CrossEncoder pipeline that can also be instantiated directly. The CrossEncoder pipeline has the same methods and functionality as described below.
Cross-encoder models are supported via the `crossencode=True` constructor parameter. Late interaction (i.e. ColBERT) models are also supported via the `lateencode=True` constructor parameter. CrossEncoder and LateEncoder pipelines back each of these models and can be instantiated directly as well.
## Example
+98
View File
@@ -0,0 +1,98 @@
# LemurTrainer
![pipeline](../../images/pipeline.png#only-light)
![pipeline](../../images/pipeline-dark.png#only-dark)
Trains a LEMUR fixed dimensional encoder for a late interaction model and corpus. Training is a separate pipeline step; the saved
artifact is then loaded through the embeddings `vectors.lemur` configuration.
`LemurTrainer` owns training-data construction, feature-model setup, epoch training and validation-based selection. The loaded LEMUR
pooler remains responsible for query-feature and document-weight encoding.
## Example
```python
from txtai.pipeline import LemurTrainer
corpus = [
"First document",
"Second document",
"Third document",
]
trainer = LemurTrainer()
trainer(
"colbert-ir/colbertv2.0",
corpus,
"lemur-model",
epochs=100,
validationsplit=0.1,
)
```
`epochs` is required so the training mode is explicit. Use `epochs=100` for the quality-oriented MLP setting. This can take hours on
a CPU. Use `epochs=0` to select deterministic random ELM features as a lower-cost fallback.
The learn distribution defaults to `learncategory="query"`. Target documents are always encoded with the data encoder, so the
default encodes selected corpus texts once as data and once as queries. Set `learncategory="data"` to reuse the data encodings, or
pass a separate iterable of texts with `learn`.
When `vectors.center` is omitted, the trainer encodes the corpus without centering, computes one mean over all corpus token rows and
uses that mean to center both data and learn vectors before fitting. The collection mean is stored in the LEMUR artifact. An explicit
`vectors.center` setting keeps its configured behavior and does not store an automatic collection mean.
Set `corpussubsetsize` to a positive integer to sample that many raw corpus texts under `seed` before either encoding pass. The
default is `None`, which uses every corpus text. `trainsubsetsize` and `learnsubsetsize` apply later, after token vectors have already
been created. `corpussubsetsize` applies to `data`; a separate `learn` iterable remains caller-sized.
For trained MLP features, set `validationsplit` to a fraction greater than zero and less than one to retain the epoch with the lowest
held-out loss. The default is `0.0`, which preserves training-loss selection. The selected one-based epoch, loss and metric are
available as `selectedepoch`, `selectedloss` and `selectionmetric` on the fitted or reloaded encoder.
MLP training displays a `tqdm` progress bar on an interactive terminal, including percent complete and the current validation loss
when `validationsplit` is enabled (or training loss otherwise). Progress output is disabled for non-interactive runs.
The artifact contains `config.json` and `model.safetensors`. It stores the inference feature model, output-normalization statistics,
token sample needed to encode documents added after training and, by default, the collection token mean. The training-only output
readout is not saved.
Load the artifact in an embeddings configuration.
```yaml
embeddings:
path: colbert-ir/colbertv2.0
vectors:
lemur:
path: lemur-model
```
## Search behavior
Loading a LEMUR artifact with a stored collection mean automatically centers both query and document token vectors with that mean.
This keeps training and search on the same representation and makes fixed vectors independent of indexing or query batch size. An
explicit `vectors.center` setting takes precedence. Older artifacts without a stored mean use the standard late-pooling fallback:
batch centering for models with multiple linear layers and no centering for models with zero or one linear layer.
LEMUR approximates standardized MaxSim targets, so useful ranking scores can be negative. txtai's dense vector path L2-normalizes the
fixed vectors and removes results with scores less than or equal to zero. This can change ordering and return fewer than the requested
number of candidates compared with raw maximum inner-product search.
The Faiss backend uses exact `IDMap,Flat` search through 5,000 rows and switches to an IVF index above that threshold. In the measured
scifact run, default IVF reduced LEMUR NDCG@10 by 43% relative to exact search, compared with 25% for MUVERA. For LEMUR corpora above
5,000 rows, either pin `faiss.components` to an exact index or tune the IVF settings for the corpus. The exact configuration is:
```yaml
embeddings:
path: colbert-ir/colbertv2.0
vectors:
lemur:
path: lemur-model
faiss:
components: IDMap,Flat
```
## Methods
Python documentation for the pipeline.
### ::: txtai.pipeline.LemurTrainer.__call__
+14
View File
@@ -98,6 +98,20 @@ See the following PEFT documentation links for more information.
- [Quantization](https://huggingface.co/docs/peft/developer_guides/quantization)
- [LoRA](https://huggingface.co/docs/peft/developer_guides/lora)
## Merge
An important parameter for `language-generation` and `language-modeling` tasks is `merge` or the packing of data into chunks.
It supports the following options.
- `concat` (default) - text is split into chunks up to maxlength, data can be split across multiple chunks
- `pack` - text is split into chunks up to maxlength, data guaranteed to be in same chunk, chunks can be smaller than maxlength
- `None` - disables merging
Merging helps reduce training time as data can be processed efficiently without padding. `concat` maximizes this as it guarantees each chunk will be up to maxlength size. `pack` is a middle ground where data is combined but records are preserved.
For general language modeling tasks like masked language modeling, `concat` is the best choice. For instruction/prompt fine-tuning, `pack` or None are the better choices as it guarantees complex logic is not split across chunks.
## Methods
Python documentation for the pipeline.
+4 -4
View File
@@ -6,9 +6,9 @@ The following applications are powered by txtai.
| Application | Description |
|:------------ |:-------------|
| [txtchat](https://github.com/neuml/txtchat) | Retrieval Augmented Generation (RAG) powered search |
| [paperai](https://github.com/neuml/paperai) | Semantic search and workflows for medical/scientific papers |
| [codequestion](https://github.com/neuml/codequestion) | Semantic search for developers |
| [tldrstory](https://github.com/neuml/tldrstory) | Semantic search for headlines and story text |
| [rag](https://github.com/neuml/rag) | Retrieval Augmented Generation (RAG) application |
| [ncoder](https://github.com/neuml/ncoder) | Open-Source AI coding agent |
| [paperai](https://github.com/neuml/paperai) | AI for medical and scientific papers |
| [annotateai](https://github.com/neuml/annotateai) | Automatically annotate papers with LLMs |
In addition to this list, there are also many other [open-source projects](https://github.com/neuml/txtai/network/dependents), [published research](https://scholar.google.com/scholar?q=txtai&hl=en&as_ylo=2022) and closed proprietary/commercial projects that have built on txtai in production.
+26 -11
View File
@@ -1,6 +1,6 @@
# Use Cases
The following sections introduce common txtai use cases. A comprehensive set of over 50 [example notebooks and applications](../examples) are also available.
The following sections introduce common txtai use cases. A comprehensive set of over 70 [example notebooks and applications](../examples) are also available.
## Semantic Search
@@ -24,11 +24,7 @@ Get started with the following examples.
## LLM Orchestration
LLM chains, retrieval augmented generation (RAG), chat with your data, pipelines and workflows that interface with large language models (LLMs).
### Chains
Integrate LLM chains (known as workflows in txtai), multiple LLM agents and self-critique.
Autonomous agents, retrieval augmented generation (RAG), chat with your data, pipelines and workflows that interface with large language models (LLMs).
![llm](images/llm.png)
@@ -40,6 +36,23 @@ See below to learn more.
| [Integrate LLM frameworks](https://github.com/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) | Integrate llama.cpp, LiteLLM and custom generation frameworks | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/53_Integrate_LLM_Frameworks.ipynb) |
| [Build knowledge graphs with LLMs](https://github.com/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) | Build knowledge graphs with LLM-driven entity extraction | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/57_Build_knowledge_graphs_with_LLM_driven_entity_extraction.ipynb) |
### Agents
Agents connect embeddings, pipelines, workflows and other agents together to autonomously solve complex problems.
![agent](images/agent.png)
txtai agents are built on top of the [smolagents](https://github.com/huggingface/smolagents) framework. This supports all LLMs txtai supports (Hugging Face, llama.cpp, OpenAI / Claude / AWS Bedrock via LiteLLM). Agent prompting with [`agents.md`](https://github.com/agentsmd/agents.md) and [`skill.md`](https://agentskills.io/specification) are also supported.
Check out this [Agent Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/agent_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Granting autonomy to agents](https://github.com/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) | Agents that iteratively solve problems as they see fit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/69_Granting_autonomy_to_agents.ipynb) |
| [TxtAI got skills](https://github.com/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) | Integrate skill.md files with your agent | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/83_TxtAI_got_skills.ipynb) |
| [Agent Tools](https://github.com/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) [▶️](https://www.youtube.com/watch?v=RDNaFXQy3GQ) | Learn about the txtai agent toolkit | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/84_Agent_Tools.ipynb) |
| [Analyzing LinkedIn Company Posts with Graphs and Agents](https://github.com/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) | Exploring how to improve social media engagement with AI | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb) |
### Retrieval augmented generation
Retrieval augmented generation (RAG) reduces the risk of LLM hallucinations by constraining the output with a knowledge base as context. RAG is commonly used to "chat with your data".
@@ -47,14 +60,14 @@ Retrieval augmented generation (RAG) reduces the risk of LLM hallucinations by c
![rag](images/rag.png#gh-light-mode-only)
![rag](images/rag-dark.png#gh-dark-mode-only)
A novel feature of txtai is that it can provide both an answer and source citation.
Check out this [RAG Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/rag_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [How RAG with txtai works](https://github.com/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) | Create RAG processes, API services and Docker instances | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/63_How_RAG_with_txtai_works.ipynb) |
| [Advanced RAG with graph path traversal](https://github.com/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) | Graph path traversal to collect complex sets of data for advanced RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/58_Advanced_RAG_with_graph_path_traversal.ipynb) |
| [Advanced RAG with guided generation](https://github.com/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) | Retrieval Augmented and Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/60_Advanced_RAG_with_guided_generation.ipynb) |
| [Build RAG pipelines with txtai](https://github.com/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) [▶️](https://www.youtube.com/watch?v=t_OeAc8NVfQ) | Guide on retrieval augmented generation including how to create citations | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/52_Build_RAG_pipelines_with_txtai.ipynb) |
| [RAG is more than Vector Search](https://github.com/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) | Context retrieval via Web, SQL and other sources | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/79_RAG_is_more_than_Vector_Search.ipynb) |
| [GraphRAG with Wikipedia and GPT OSS](https://github.com/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) | Deep graph search powered RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb) |
| [Speech to Speech RAG](https://github.com/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) [▶️](https://www.youtube.com/watch?v=tH8QWwkVMKA) | Full cycle speech to speech workflow with RAG | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/65_Speech_to_Speech_RAG.ipynb) |
## Language Model Workflows
@@ -65,6 +78,8 @@ Language model workflows, also known as semantic workflows, connect language mod
While LLMs are powerful, there are plenty of smaller, more specialized models that work better and faster for specific tasks. This includes models for extractive question-answering, automatic summarization, text-to-speech, transcription and translation.
Check out this [Workflow Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/workflow_quickstart.py). Additional examples are listed below.
| Notebook | Description | |
|:----------|:-------------|------:|
| [Run pipeline workflows](https://github.com/neuml/txtai/blob/master/examples/14_Run_pipeline_workflows.ipynb) [▶️](https://www.youtube.com/watch?v=UBMPDCn1gEU) | Simple yet powerful constructs to efficiently process data | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/14_Run_pipeline_workflows.ipynb) |
+3 -3
View File
@@ -133,7 +133,7 @@ Workflows can connect multiple LLM prompting tasks together.
```yaml
llm:
path: google/flan-t5-xl
path: openai/gpt-oss-20b
workflow:
llm:
@@ -168,7 +168,7 @@ Any txtai pipeline/workflow task can be connected in workflows with LLMs.
```yaml
llm:
path: google/flan-t5-xl
path: openai/gpt-oss-20b
translation:
@@ -202,4 +202,4 @@ Workflows are callable objects. Workflows take an input of iterable data element
## More examples
See [this link](../examples/#workflows) for a full list of workflow examples.
Check out this [Workflow Quickstart Example](https://github.com/neuml/txtai/blob/master/examples/workflow_quickstart.py). See [this link](../examples/#workflows) for a full list of workflow examples.
+3 -2
View File
@@ -22,8 +22,9 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: console
name:
tasks:
- task: console
```
## Methods
+3 -2
View File
@@ -22,8 +22,9 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: export
name:
tasks:
- task: export
```
## Methods
+3 -2
View File
@@ -22,8 +22,9 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: file
name:
tasks:
- task: file
```
## Methods
+3 -2
View File
@@ -22,8 +22,9 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: image
name:
tasks:
- task: image
```
## Methods
+17 -3
View File
@@ -35,12 +35,26 @@ Tasks can also be created with configuration as part of a workflow.
```yaml
workflow:
tasks:
- action: summary
name:
tasks:
- action: summary
```
::: txtai.workflow.Task.__init__
## Multi-action task inputs
A multi-action `Task` requires reusable inputs. Passing a single-pass iterator, such as a generator or the output of a `StreamTask`, raises a `ValueError` before consuming inputs or running any actions. Automatically buffering an iterator could exhaust memory, so tasks do not convert these inputs to a list.
Iterators passed to a `Workflow` remain supported: the workflow collects bounded batches before passing them to its tasks. For example:
```python
workflow = Workflow([Task([list, list])], batch=2)
list(workflow(iter([1, 2, 3]))) # [(1, 1), (2, 2), (3, 3)]
```
This batching occurs at the workflow input; it does not batch iterator outputs produced by tasks inside that workflow. Single-action tasks continue to accept iterator inputs.
## Multi-action task concurrency
The default processing mode is to run actions sequentially. Multiprocessing support is already built in at a number of levels. Any of the GPU models will maximize GPU utilization for example and even in CPU mode, concurrency is utilized. But there are still use cases for task action concurrency. For example, if the system has multiple GPUs, the task runs external sequential code, or the task has a large number of I/O tasks.
@@ -72,7 +86,7 @@ workflow = Workflow([Task(lambda x: [y * 3 for y in x], unpack=False, column=0)]
list(workflow([(2, 8)]))
```
For the example input tuple of (2, 2), the workflow will only select the first element (2) and run the task against that element.
For the example input tuple of (2, 8), the workflow will only select the first element (2) and run the task against that element.
```python
workflow = Workflow([Task([lambda x: [y * 3 for y in x],
+4 -3
View File
@@ -22,9 +22,10 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: retrieve
directory: /tmp
name:
tasks:
- task: retrieve
directory: /tmp
```
## Methods
+4 -3
View File
@@ -22,9 +22,10 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: service
url: https://service.url/action
name:
tasks:
- task: service
url: https://service.url/action
```
## Methods
+3 -2
View File
@@ -22,8 +22,9 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: storage
name:
tasks:
- task: storage
```
## Methods
+4 -3
View File
@@ -23,9 +23,10 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: template
template: This is a {text} task
name:
tasks:
- task: template
template: This is a {text} task
```
## Methods
+3 -2
View File
@@ -22,8 +22,9 @@ This task can also be created with workflow configuration.
```yaml
workflow:
tasks:
- task: url
name:
tasks:
- task: url
```
## Methods
File diff suppressed because one or more lines are too long
@@ -1,15 +1,4 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
@@ -21,7 +10,7 @@
"\n",
"In Part 1, we gave a general overview of txtai, the backing technology and examples of how to use it for similarity searches. Part 2 covered an embedding index with a larger dataset.\n",
"\n",
"For real world large-scale use cases, data is often stored in a database (Elasticsearch, SQL, MongoDB, files, etc). Here we'll show how to read from SQLite, build a Embedding index backed by word embeddings and run queries against the generated Embeddings index.\n",
"For real world large-scale use cases, data is often stored in a database (Elasticsearch, SQL, MongoDB, files, etc). Here we'll show how to read from SQLite, build an Embedding index and run queries against the generated Embeddings index.\n",
"\n",
"This example covers functionality found in the [paperai](https://github.com/neuml/paperai) library. See that library for a full solution that can be used with the dataset discussed below."
]
@@ -34,20 +23,20 @@
"source": [
"# Install dependencies\n",
"\n",
"Install `txtai` and all dependencies. Since this notebook is building word vectors, we need to install the similarity extras package."
"Install `txtai` and all dependencies."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "czPYSA2Q9ZHO"
},
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[similarity]"
],
"execution_count": null,
"outputs": []
"!pip install git+https://github.com/neuml/txtai"
]
},
{
"cell_type": "markdown",
@@ -64,93 +53,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "TONQ4_Kv9dtd"
},
"outputs": [],
"source": [
"%%capture\n",
"!wget https://github.com/neuml/txtai/releases/download/v1.1.0/tests.gz\n",
"!gunzip tests.gz\n",
"!mv tests articles.sqlite"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "bzdaJiZYBIHE"
},
"source": [
"# Build Word Vectors\n",
"\n",
"This example will build a search system backed by word embeddings. Word embeddings provide a good tradeoff of performance to functionality for a similarity search system. With that being said, transformer models are making great progress in scaling performance down to smaller models and are the preferred vector backend for txtai in most cases.\n",
"\n",
"For this notebook, we'll build our own custom embeddings for demo purposes. A number of pre-trained word embedding models are available:\n",
"\n",
" - [General language models from pymagnitude](https://github.com/plasticityai/magnitude)\n",
" - [CORD-19 fastText](https://www.kaggle.com/davidmezzetti/cord19-fasttext-vectors)"
]
},
{
"cell_type": "code",
"metadata": {
"id": "fJcn-CAH-u3K",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "ab5a4340-13fc-4b47-b881-9388e2534ece"
},
"source": [
"import os\n",
"import sqlite3\n",
"import tempfile\n",
"\n",
"from txtai.pipeline import Tokenizer\n",
"from txtai.vectors import WordVectors\n",
"\n",
"print(\"Streaming tokens to temporary file\")\n",
"\n",
"# Stream tokens to temp working file\n",
"with tempfile.NamedTemporaryFile(mode=\"w\", suffix=\".txt\", delete=False) as output:\n",
" # Save file path\n",
" tokens = output.name\n",
"\n",
" db = sqlite3.connect(\"articles.sqlite\")\n",
" cur = db.cursor()\n",
" cur.execute(\"SELECT Text from sections\")\n",
"\n",
" for row in cur:\n",
" output.write(\" \".join(Tokenizer.tokenize(row[0])) + \"\\n\")\n",
"\n",
" # Free database resources\n",
" db.close()\n",
"\n",
"# Build word vectors model - 300 dimensions, 3 min occurrences\n",
"WordVectors.build(tokens, 300, 3, \"cord19-300d\")\n",
"\n",
"# Remove temporary tokens file\n",
"os.remove(tokens)\n",
"\n",
"# Show files\n",
"!ls -l"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Streaming tokens to temporary file\n",
"Building 300 dimension model\n",
"Converting vectors to magnitude format\n",
"total 78948\n",
"-rw-r--r-- 1 root root 8065024 Dec 7 15:48 articles.sqlite\n",
"-rw-r--r-- 1 root root 24145920 Dec 27 17:42 cord19-300d.magnitude\n",
"-rw-r--r-- 1 root root 48625387 Dec 27 17:41 cord19-300d.txt\n",
"drwxr-xr-x 1 root root 4096 Dec 3 14:33 sample_data\n"
]
}
]
},
{
@@ -161,25 +73,34 @@
"source": [
"# Build an embeddings index\n",
"\n",
"The following steps build an embeddings index using the word vector model just created. This model builds a BM25 + fastText index. BM25 is used to build a weighted average of the word embeddings for a section. More information on this method can be found in this [Medium article](https://towardsdatascience.com/building-a-sentence-embedding-index-with-fasttext-and-bm25-f07e7148d240?gi=79da927aa10)."
"The following steps build an embeddings index using a vector model designed for medical papers, [PubMedBERT Embeddings](https://huggingface.co/NeuML/pubmedbert-base-embeddings)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "5PrrxGRPGHqX",
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5PrrxGRPGHqX",
"outputId": "61bf7211-6757-4147-8f2f-e4d1ebe58e11"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Iterated over 21499 total rows\n"
]
}
],
"source": [
"import sqlite3\n",
"\n",
"import regex as re\n",
"\n",
"from txtai.embeddings import Embeddings\n",
"from txtai.pipeline import Tokenizer\n",
"from txtai import Embeddings\n",
"\n",
"def stream():\n",
" # Connection to database file\n",
@@ -196,46 +117,24 @@
"\n",
" # Only process certain document sections\n",
" if not name or not re.search(r\"background|(?<!.*?results.*?)discussion|introduction|reference\", name.lower()):\n",
" # Tokenize text\n",
" tokens = Tokenizer.tokenize(text)\n",
"\n",
" document = (uid, tokens, None)\n",
" document = (uid, text, None)\n",
"\n",
" count += 1\n",
" if count % 1000 == 0:\n",
" print(\"Streamed %d documents\" % (count), end=\"\\r\")\n",
"\n",
" # Skip documents with no tokens parsed\n",
" if tokens:\n",
" yield document\n",
" yield document\n",
"\n",
" print(\"Iterated over %d total rows\" % (count))\n",
"\n",
" # Free database resources\n",
" db.close()\n",
"\n",
"# BM25 + fastText vectors\n",
"embeddings = Embeddings({\"path\": \"cord19-300d.magnitude\",\n",
" \"scoring\": \"bm25\",\n",
" \"pca\": 3})\n",
"\n",
"# Build scoring index if scoring method provided\n",
"if embeddings.config.get(\"scoring\"):\n",
" embeddings.score(stream())\n",
"# Create embeddings index \n",
"embeddings = Embeddings(path=\"neuml/pubmedbert-base-embeddings\")\n",
"\n",
"# Build embeddings index\n",
"embeddings.index(stream())\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Iterated over 21499 total rows\n",
"Iterated over 21499 total rows\n"
]
}
]
},
{
@@ -251,14 +150,70 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"id": "CRbDhvvDKEl-",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 293
},
"id": "CRbDhvvDKEl-",
"outputId": "774f8085-01db-49e2-f025-4fe68afca594"
},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Title</th>\n",
" <th>Published</th>\n",
" <th>Reference</th>\n",
" <th>Match</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Management of osteoarthritis during COVID‐19 pandemic</td>\n",
" <td>2020-05-21 00:00:00</td>\n",
" <td>https://doi.org/10.1002/cpt.1910</td>\n",
" <td>Indeed, risk factors are sex, obesity, genetic factors and mechanical factors (3) .</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Does apolipoprotein E genotype predict COVID-19 severity?</td>\n",
" <td>2020-04-27 00:00:00</td>\n",
" <td>https://doi.org/10.1093/qjmed/hcaa142</td>\n",
" <td>Risk factors associated with subsequent death include older age, hypertension, diabetes, ischemic heart disease, obesity and chronic lung disease; however, sometimes there are no obvious risk factors .</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Prevalence and Impact of Myocardial Injury in Patients Hospitalized with COVID-19 Infection</td>\n",
" <td>2020-04-24 00:00:00</td>\n",
" <td>http://medrxiv.org/cgi/content/short/2020.04.20.20072702v1?rss=1</td>\n",
" <td>This risk was consistent across patients stratified by history of CVD, risk factors but no CVD, and neither CVD nor risk factors.</td>\n",
" </tr>\n",
" <tr>\n",
" <td>COVID-19 and associations with frailty and multimorbidity: a prospective analysis of UK Biobank participants</td>\n",
" <td>2020-07-23 00:00:00</td>\n",
" <td>https://www.ncbi.nlm.nih.gov/pubmed/32705587/</td>\n",
" <td>BACKGROUND: Frailty and multimorbidity have been suggested as risk factors for severe COVID-19 disease.</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Risk Stratification for Healthcare workers during the CoViD-19 Pandemic; using demographics, co-morbid disease and clinical domain in order to assign clinical duties</td>\n",
" <td>2020-05-09 00:00:00</td>\n",
" <td>http://medrxiv.org/cgi/content/short/2020.05.05.20091967v1?rss=1</td>\n",
" <td>Vascular disease, diabetes and chronic pulmonary disease further increased risk.</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"\n",
@@ -291,62 +246,6 @@
"# file.write(htmlData)\n",
"\n",
"display(HTML(df.to_html(index=False)))"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Title</th>\n",
" <th>Published</th>\n",
" <th>Reference</th>\n",
" <th>Match</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Management of osteoarthritis during COVID‐19 pandemic</td>\n",
" <td>2020-05-21 00:00:00</td>\n",
" <td>https://doi.org/10.1002/cpt.1910</td>\n",
" <td>Indeed, risk factors are sex, obesity, genetic factors and mechanical factors (3) .</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Work-related and Personal Factors Associated with Mental Well-being during COVID-19 Response: A Survey of Health Care and Other Workers</td>\n",
" <td>2020-06-11 00:00:00</td>\n",
" <td>http://medrxiv.org/cgi/content/short/2020.06.09.20126722v1?rss=1</td>\n",
" <td>Poor family supportive behaviors by supervisors were also associated with these outcomes [1.40 (1.21 - 1.62), 1.69 (1.48 - 1.92), 1.54 (1.44 - 1.64)].</td>\n",
" </tr>\n",
" <tr>\n",
" <td>No evidence that androgen regulation of pulmonary TMPRSS2 explains sex-discordant COVID-19 outcomes</td>\n",
" <td>2020-04-21 00:00:00</td>\n",
" <td>https://doi.org/10.1101/2020.04.21.051201</td>\n",
" <td>In addition to male sex, smoking is a risk factor for COVID-19 susceptibility and poor clinical outcomes .</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Current status of potential therapeutic candidates for the COVID-19 crisis</td>\n",
" <td>2020-04-22 00:00:00</td>\n",
" <td>https://doi.org/10.1016/j.bbi.2020.04.046</td>\n",
" <td>There was no difference on 28-day mortality between heparin users and nonusers.</td>\n",
" </tr>\n",
" <tr>\n",
" <td>COVID-19: what has been learned and to be learned about the novel coronavirus disease</td>\n",
" <td>2020-03-15 00:00:00</td>\n",
" <td>https://doi.org/10.7150/ijbs.45134</td>\n",
" <td>• Three major risk factors for COVID-19 were sex (male), age (≥60), and severe pneumonia.</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {}
}
]
},
{
@@ -362,29 +261,98 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "TLVOTQJchvTi"
},
"outputs": [],
"source": [
"%%capture\n",
"from txtai.pipeline import Extractor\n",
"\n",
"# Create extractor instance using qa model designed for the CORD-19 dataset\n",
"# Note: That extractive QA was a predecessor to Large Language Models (LLMs). LLMs likely will get better results.\n",
"extractor = Extractor(embeddings, \"NeuML/bert-small-cord19qa\")"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"id": "19fmKawThs6d",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 293
},
"id": "19fmKawThs6d",
"outputId": "b7cd40e3-a87c-419d-f520-b7795607cebc"
},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Title</th>\n",
" <th>Published</th>\n",
" <th>Reference</th>\n",
" <th>Match</th>\n",
" <th>Risk Factors</th>\n",
" <th>Locations</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Management of osteoarthritis during COVID‐19 pandemic</td>\n",
" <td>2020-05-21 00:00:00</td>\n",
" <td>https://doi.org/10.1002/cpt.1910</td>\n",
" <td>Indeed, risk factors are sex, obesity, genetic factors and mechanical factors (3) .</td>\n",
" <td>sex, obesity, genetic factors and mechanical factors</td>\n",
" <td>hospitals and clinics</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Does apolipoprotein E genotype predict COVID-19 severity?</td>\n",
" <td>2020-04-27 00:00:00</td>\n",
" <td>https://doi.org/10.1093/qjmed/hcaa142</td>\n",
" <td>Risk factors associated with subsequent death include older age, hypertension, diabetes, ischemic heart disease, obesity and chronic lung disease; however, sometimes there are no obvious risk factors .</td>\n",
" <td>None</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Prevalence and Impact of Myocardial Injury in Patients Hospitalized with COVID-19 Infection</td>\n",
" <td>2020-04-24 00:00:00</td>\n",
" <td>http://medrxiv.org/cgi/content/short/2020.04.20.20072702v1?rss=1</td>\n",
" <td>This risk was consistent across patients stratified by history of CVD, risk factors but no CVD, and neither CVD nor risk factors.</td>\n",
" <td>neither CVD nor risk factors</td>\n",
" <td>Mount Sinai Health System</td>\n",
" </tr>\n",
" <tr>\n",
" <td>COVID-19 and associations with frailty and multimorbidity: a prospective analysis of UK Biobank participants</td>\n",
" <td>2020-07-23 00:00:00</td>\n",
" <td>https://www.ncbi.nlm.nih.gov/pubmed/32705587/</td>\n",
" <td>BACKGROUND: Frailty and multimorbidity have been suggested as risk factors for severe COVID-19 disease.</td>\n",
" <td>Frailty and multimorbidity</td>\n",
" <td>213 countries and territories</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Risk Stratification for Healthcare workers during the CoViD-19 Pandemic; using demographics, co-morbid disease and clinical domain in order to assign clinical duties</td>\n",
" <td>2020-05-09 00:00:00</td>\n",
" <td>http://medrxiv.org/cgi/content/short/2020.05.05.20091967v1?rss=1</td>\n",
" <td>Vascular disease, diabetes and chronic pulmonary disease further increased risk.</td>\n",
" <td>Vascular disease, diabetes and chronic pulmonary disease</td>\n",
" <td>None</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"db = sqlite3.connect(\"articles.sqlite\")\n",
"cur = db.cursor()\n",
@@ -415,74 +383,6 @@
"\n",
"df = pd.DataFrame(results, columns=[\"Title\", \"Published\", \"Reference\", \"Match\", \"Risk Factors\", \"Locations\"])\n",
"display(HTML(df.to_html(index=False)))"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>Title</th>\n",
" <th>Published</th>\n",
" <th>Reference</th>\n",
" <th>Match</th>\n",
" <th>Risk Factors</th>\n",
" <th>Locations</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Management of osteoarthritis during COVID‐19 pandemic</td>\n",
" <td>2020-05-21 00:00:00</td>\n",
" <td>https://doi.org/10.1002/cpt.1910</td>\n",
" <td>Indeed, risk factors are sex, obesity, genetic factors and mechanical factors (3) .</td>\n",
" <td>sex, obesity, genetic factors and mechanical factors</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Work-related and Personal Factors Associated with Mental Well-being during COVID-19 Response: A Survey of Health Care and Other Workers</td>\n",
" <td>2020-06-11 00:00:00</td>\n",
" <td>http://medrxiv.org/cgi/content/short/2020.06.09.20126722v1?rss=1</td>\n",
" <td>Poor family supportive behaviors by supervisors were also associated with these outcomes [1.40 (1.21 - 1.62), 1.69 (1.48 - 1.92), 1.54 (1.44 - 1.64)].</td>\n",
" <td>Poor family supportive behaviors</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <td>No evidence that androgen regulation of pulmonary TMPRSS2 explains sex-discordant COVID-19 outcomes</td>\n",
" <td>2020-04-21 00:00:00</td>\n",
" <td>https://doi.org/10.1101/2020.04.21.051201</td>\n",
" <td>In addition to male sex, smoking is a risk factor for COVID-19 susceptibility and poor clinical outcomes .</td>\n",
" <td>Higher morbidity and mortality</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Current status of potential therapeutic candidates for the COVID-19 crisis</td>\n",
" <td>2020-04-22 00:00:00</td>\n",
" <td>https://doi.org/10.1016/j.bbi.2020.04.046</td>\n",
" <td>There was no difference on 28-day mortality between heparin users and nonusers.</td>\n",
" <td>elicited strong inflammatory responses are favorable or detrimental</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <td>COVID-19: what has been learned and to be learned about the novel coronavirus disease</td>\n",
" <td>2020-03-15 00:00:00</td>\n",
" <td>https://doi.org/10.7150/ijbs.45134</td>\n",
" <td>• Three major risk factors for COVID-19 were sex (male), age (≥60), and severe pneumonia.</td>\n",
" <td>sex (male), age (≥60), and severe pneumonia</td>\n",
" <td>None</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {}
}
]
},
{
@@ -494,5 +394,29 @@
"In the example above, the Embeddings index is used to find the top N results for a given query. On top of that, a question-answer extractor is used to derive additional columns based on a list of questions. In this case, the \"Risk Factors\" and \"Location\" columns were pulled from the document text."
]
}
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "local",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.21"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+1 -1
View File
@@ -429,7 +429,7 @@
"source": [
"# External vector models\n",
"\n",
"txtai supports generating vectors with [Hugging Face Transformers](https://github.com/huggingface/transformers), [PyTorch](https://github.com/pytorch/pytorch), [ONNX](https://github.com/microsoft/onnxruntime) and [Word Vector](https://github.com/neuml/magnitude) models.\n",
"txtai supports generating vectors with [Hugging Face Transformers](https://github.com/huggingface/transformers), [PyTorch](https://github.com/pytorch/pytorch), [ONNX](https://github.com/microsoft/onnxruntime) and [Word Vector](https://github.com/neuml/staticvectors) models.\n",
"\n",
"This release adds support for pre-computed vectors using external models. External models may be an API, custom library and/or another way to vectorize data. This adds flexibility given the high computation cost in building embeddings vectors. Embeddings generation could be outsourced or consolidated to a group of servers with GPUs, leaving index servers to run on lower resourced machines. \n",
"\n",
+197 -198
View File
@@ -1,28 +1,4 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.7.6",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"colab": {
"provenance": []
}
},
"cells": [
{
"cell_type": "markdown",
@@ -61,44 +37,59 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
"trusted": true,
"_kg_hide-output": true,
"id": "24q-1n5i6XzQ"
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
"id": "24q-1n5i6XzQ",
"trusted": true
},
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline]"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0p3WCDniUths"
},
"source": [
"# Create index\n",
"Let's first recap how to create an index. We'll use the classic txtai example.\n"
],
"metadata": {
"id": "0p3WCDniUths"
}
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"_uuid": "d629ff2d2480ee46fbb7e2d37f6b5fab8052498a",
"_cell_guid": "79c7e3d0-c299-4dcb-8224-4455121ee9b0",
"trusted": true,
"id": "2j_CFGDR6Xzp",
"_uuid": "d629ff2d2480ee46fbb7e2d37f6b5fab8052498a",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "e65238c5-d67f-4fe4-9cbf-c88b0ff3a8bb"
"id": "2j_CFGDR6Xzp",
"outputId": "e65238c5-d67f-4fe4-9cbf-c88b0ff3a8bb",
"trusted": true
},
"outputs": [
{
"data": {
"text/plain": [
"[{'id': '4',\n",
" 'text': 'Maine man wins $1M from $25 lottery ticket',\n",
" 'score': 0.08329025655984879}]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from txtai.embeddings import Embeddings\n",
"from txtai import Embeddings\n",
"\n",
"data = [\"US tops 5 million confirmed virus cases\",\n",
" \"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg\",\n",
@@ -108,65 +99,29 @@
" \"Make huge profits without work, earn up to $100,000 a day\"]\n",
"\n",
"# Create embeddings index with content enabled. The default behavior is to only store indexed vectors.\n",
"embeddings = Embeddings({\"path\": \"sentence-transformers/nli-mpnet-base-v2\", \"content\": True})\n",
"embeddings = Embeddings(path=\"sentence-transformers/nli-mpnet-base-v2\", content=True)\n",
"\n",
"# Create an index for the list of text\n",
"embeddings.index([(uid, text, None) for uid, text in enumerate(data)])\n",
"embeddings.index(data)\n",
"\n",
"# Run a search\n",
"embeddings.search(\"feel good story\", 1)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[{'id': '4',\n",
" 'score': 0.08329011499881744,\n",
" 'text': 'Maine man wins $1M from $25 lottery ticket'}]"
]
},
"metadata": {},
"execution_count": 30
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "QTee7YMNDD4R"
},
"source": [
"# Query translation models\n",
"\n",
"Next we'll explore how query translation models work with examples. "
],
"metadata": {
"id": "QTee7YMNDD4R"
}
]
},
{
"cell_type": "code",
"source": [
"from txtai.pipeline import Sequences\n",
"\n",
"sequences = Sequences(\"NeuML/t5-small-txtsql\")\n",
"\n",
"queries = [\n",
" \"feel good story\",\n",
" \"feel good story since yesterday\",\n",
" \"feel good story with lottery in text\",\n",
" \"how many feel good story\",\n",
" \"feel good story translated to fr\",\n",
" \"feel good story summarized\"\n",
"]\n",
"\n",
"# Prefix to pass to T5 model\n",
"prefix = \"translate English to SQL: \"\n",
"\n",
"for query in queries:\n",
" print(f\"Input: {query}\")\n",
" print(f\"SQL: {sequences(query, prefix)}\")\n",
" print()\n"
],
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -174,11 +129,10 @@
"id": "04iOgP_ojSfK",
"outputId": "41e73130-75e6-4ae9-b690-685972a13565"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"Input: feel good story\n",
"SQL: select id, text, score from txtai where similar('feel good story')\n",
@@ -186,8 +140,8 @@
"Input: feel good story since yesterday\n",
"SQL: select id, text, score from txtai where similar('feel good story') and entry >= date('now', '-1 day')\n",
"\n",
"Input: feel good story with lottery in text\n",
"SQL: select id, text, score from txtai where similar('feel good story') and text like '% lottery%'\n",
"Input: feel good story with 'lottery' in text\n",
"SQL: select id, text, score from txtai where similar('feel good story') and text like '%lottery%'\n",
"\n",
"Input: how many feel good story\n",
"SQL: select count(*) from txtai where similar('feel good story')\n",
@@ -200,32 +154,73 @@
"\n"
]
}
],
"source": [
"from txtai import LLM\n",
"\n",
"llm = LLM(\"NeuML/t5-small-txtsql\", template=\"translate English to SQL: {text}\")\n",
"\n",
"queries = [\n",
" \"feel good story\",\n",
" \"feel good story since yesterday\",\n",
" \"feel good story with 'lottery' in text\",\n",
" \"how many feel good story\",\n",
" \"feel good story translated to fr\",\n",
" \"feel good story summarized\"\n",
"]\n",
"\n",
"for query in queries:\n",
" print(f\"Input: {query}\")\n",
" print(f\"SQL: {llm(query)}\")\n",
" print()\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "rAnEMaiWlOXm"
},
"source": [
"Looking at the query translations above gives an idea on how this model works.\n",
"\n",
"[t5-small-txtsql](https://huggingface.co/NeuML/t5-small-txtsql) is the default model. Custom domain query syntax languages can be created using this same methodology, including for other languages. Natural language can be translated to functions, query clauses, column selection and more!"
],
"metadata": {
"id": "rAnEMaiWlOXm"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "P9hOcgNfjSyL"
},
"source": [
"# Natural language filtering\n",
"\n",
"Now it's time for this in action! Let's first initialize the embeddings index with the appropriate settings."
],
"metadata": {
"id": "P9hOcgNfjSyL"
}
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "L2DDJrd0RAaN",
"outputId": "c60bfc29-187b-4926-8656-04063b2ca85c"
},
"outputs": [
{
"data": {
"text/plain": [
"{'id': '4',\n",
" 'score': 0.08329025655984879,\n",
" 'text': 'Maine Mann gewinnt $1M von $25 Lotterie-Ticket'}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from txtai.pipeline import Translation\n",
"\n",
@@ -235,56 +230,34 @@
"translation = Translation()\n",
"\n",
"# Create embeddings index with content enabled. The default behavior is to only store indexed vectors.\n",
"embeddings = Embeddings({\"path\": \"sentence-transformers/nli-mpnet-base-v2\",\n",
" \"content\": True,\n",
" \"query\": {\"path\": \"NeuML/t5-small-txtsql\"},\n",
" \"functions\": [translate]})\n",
"embeddings = Embeddings(\n",
" path=\"sentence-transformers/nli-mpnet-base-v2\",\n",
" content=True,\n",
" query={\"path\": \"NeuML/t5-small-txtsql\"},\n",
" functions=[translate]\n",
")\n",
"\n",
"# Create an index for the list of text\n",
"embeddings.index([(uid, text, None) for uid, text in enumerate(data)])\n",
"embeddings.index(data)\n",
"\n",
"query = \"select id, score, translate(text, 'de') 'text' from txtai where similar('feel good story')\"\n",
"\n",
"# Run a search using a custom SQL function\n",
"embeddings.search(query)[0]"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "L2DDJrd0RAaN",
"outputId": "c60bfc29-187b-4926-8656-04063b2ca85c"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'id': '4',\n",
" 'score': 0.08329011499881744,\n",
" 'text': 'Maine Mann gewinnt $1M von $25 Lotterie-Ticket'}"
]
},
"metadata": {},
"execution_count": 32
}
]
},
{
"cell_type": "markdown",
"source": [
"Note how the query model was provided as a embeddings index configuration parameter. Custom SQL functions were also added in. Let's now see if the same SQL statement can be run with a natural language query."
],
"metadata": {
"id": "MNd7QmFmnh-f"
}
},
"source": [
"Note how the query model was provided as a embeddings index configuration parameter. Custom SQL functions were also added in. Let's now see if the same SQL statement can be run with a natural language query."
]
},
{
"cell_type": "code",
"source": [
"embeddings.search(\"feel good story translated to de\")[0]"
],
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -292,36 +265,36 @@
"id": "mnGSBNMonur2",
"outputId": "dc14d898-b46f-42e6-88e0-434863cc15d6"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'id': '4',\n",
" 'score': 0.08329011499881744,\n",
" 'text': 'Maine Mann gewinnt $1M von $25 Lotterie-Ticket'}"
" 'text': 'Maine Mann gewinnt $1M von $25 Lotterie-Ticket',\n",
" 'score': 0.08329025655984879}"
]
},
"execution_count": 4,
"metadata": {},
"execution_count": 33
"output_type": "execute_result"
}
],
"source": [
"embeddings.search(\"feel good story translated to de\")[0]"
]
},
{
"cell_type": "markdown",
"source": [
"Same result. Let's try a few more."
],
"metadata": {
"id": "OnmVUK2DoZkh"
}
},
"source": [
"Same result. Let's try a few more."
]
},
{
"cell_type": "code",
"source": [
"embeddings.search(\"feel good story since yesterday\")[0]"
],
"execution_count": 5,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -329,27 +302,27 @@
"id": "Js2b_M61oitg",
"outputId": "fab080cb-d082-4cf3-8314-12d23acc3c02"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'id': '4',\n",
" 'score': 0.08329011499881744,\n",
" 'text': 'Maine man wins $1M from $25 lottery ticket'}"
" 'text': 'Maine man wins $1M from $25 lottery ticket',\n",
" 'score': 0.08329025655984879}"
]
},
"execution_count": 5,
"metadata": {},
"execution_count": 34
"output_type": "execute_result"
}
],
"source": [
"embeddings.search(\"feel good story since yesterday\")[0]"
]
},
{
"cell_type": "code",
"source": [
"embeddings.search(\"feel good story with lottery in text\")[0]"
],
"execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -357,36 +330,36 @@
"id": "pcxPgriwomWv",
"outputId": "7e71dd09-7c4f-4147-ba9e-47a45c1cf90f"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'id': '4',\n",
" 'score': 0.08329011499881744,\n",
" 'text': 'Maine man wins $1M from $25 lottery ticket'}"
"[{'id': '4',\n",
" 'text': 'Maine man wins $1M from $25 lottery ticket',\n",
" 'score': 0.08329025655984879}]"
]
},
"execution_count": 6,
"metadata": {},
"execution_count": 35
"output_type": "execute_result"
}
],
"source": [
"embeddings.search(\"feel good story with 'lottery' in text\")"
]
},
{
"cell_type": "markdown",
"source": [
"For good measure, a couple queries with filters that return no results."
],
"metadata": {
"id": "1ob4Q_CLpGBm"
}
},
"source": [
"For good measure, a couple queries with filters that return no results."
]
},
{
"cell_type": "code",
"source": [
"embeddings.search(\"feel good story with missing in text\")"
],
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -394,25 +367,25 @@
"id": "LMaf7JJzonAC",
"outputId": "71080bd1-2d9e-41ba-9501-2cdedaf26d6d"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 7,
"metadata": {},
"execution_count": 36
"output_type": "execute_result"
}
],
"source": [
"embeddings.search(\"feel good story with missing in text\")"
]
},
{
"cell_type": "code",
"source": [
"embeddings.search(\"feel good story with field equal 14\")"
],
"execution_count": 8,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -420,33 +393,57 @@
"id": "ADFNLhvto_0J",
"outputId": "12e08ea8-7203-4fb0-cb84-1133b5db9dc0"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 8,
"metadata": {},
"execution_count": 37
"output_type": "execute_result"
}
],
"source": [
"embeddings.search(\"feel good story with field equal 14\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "mTT8nopiRdVH"
},
"source": [
"# Query translation with applications\n",
"\n",
"Of course this is all available with YAML-configured applications."
],
"metadata": {
"id": "mTT8nopiRdVH"
}
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "FZ_7G6M4RUbz",
"outputId": "b00ce1c2-8df2-4289-8d03-991174a0e74f"
},
"outputs": [
{
"data": {
"text/plain": [
"{'id': '4',\n",
" 'text': 'Maine Mann gewinnt $1M von $25 Lotterie-Ticket',\n",
" 'score': 0.08329025655984879}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"config = \"\"\"\n",
"translation:\n",
@@ -470,28 +467,6 @@
"\n",
"# Run search query\n",
"app.search(\"feel good story translated to de\")[0]"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "FZ_7G6M4RUbz",
"outputId": "b00ce1c2-8df2-4289-8d03-991174a0e74f"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'id': '4',\n",
" 'score': 0.08329011499881744,\n",
" 'text': 'Maine Mann gewinnt $1M von $25 Lotterie-Ticket'}"
]
},
"metadata": {},
"execution_count": 38
}
]
},
{
@@ -505,5 +480,29 @@
"This notebook introduced natural language filtering with query translation models. This powerful feature adds filtering and pipelines to natural language statements. Custom domain-specific query languages can be created to enable rich queries natively in txtai."
]
}
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "local",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.19"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
File diff suppressed because one or more lines are too long
@@ -30,6 +30,7 @@
"- Changing the vocabulary size\n",
"- Changing the number of hidden dimensions\n",
"- Changing the number of attention heads or layers\n",
"- Create a custom model architecture\n",
"\n",
"This notebook will show how to build a new tokenizer and train a small language model (known as a micromodel) from scratch.\n"
],
+164 -307
View File
@@ -1,17 +1,4 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "markdown",
@@ -44,15 +31,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "LPQTb25tASIG"
},
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai datasets"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
@@ -71,32 +58,65 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "OUc9gqTyAYnm"
},
"outputs": [],
"source": [
"%%capture\n",
"\n",
"from txtai import Embeddings, RAG\n",
"\n",
"# Create embeddings model with content support\n",
"embeddings = Embeddings({\"path\": \"sentence-transformers/all-MiniLM-L6-v2\", \"content\": True})\n",
"embeddings = Embeddings(path=\"sentence-transformers/all-MiniLM-L6-v2\", content=True)\n",
"\n",
"# Create RAG instance\n",
"rag = RAG(embeddings, \"google/flan-t5-base\")"
],
"execution_count": null,
"outputs": []
"# Create the RAG pipeline\n",
"rag = RAG(embeddings, \"Qwen/Qwen3-4B-Instruct-2507\", template=\"\"\"\n",
" Answer the following question using the provided context.\n",
"\n",
" Question:\n",
" {question}\n",
"\n",
" Context:\n",
" {context}\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "4X5z3UjnAGe7",
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "4X5z3UjnAGe7",
"outputId": "cacb7e9d-471a-437d-c68d-a8b51f876413"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"---- Red Sox - Blue Jays ----\n",
"{'answer': 'The Blue Jays won the game.'}\n",
"{'answer': 'The score was 2-1 in favor of the Blue Jays.'}\n",
"\n",
"---- Phillies - Braves ----\n",
"{'answer': 'The Phillies won the game.'}\n",
"{'answer': 'The score was 5-0 in favor of the Phillies.'}\n",
"\n",
"---- Dodgers - Giants ----\n",
"{'answer': 'The Giants won the game.'}\n",
"{'answer': 'The score was Giants 5, Dodgers 4.'}\n",
"\n",
"---- Flyers - Lightning ----\n",
"{'answer': 'The Flyers won the game.'}\n",
"{'answer': 'The score was Flyers 4, Lightning 1.'}\n",
"\n"
]
}
],
"source": [
"data = [\"Giants hit 3 HRs to down Dodgers\",\n",
" \"Giants 5 Dodgers 4 final\",\n",
@@ -111,88 +131,40 @@
" \"Flyers 4 Lightning 1 final\",\n",
" \"Flyers win 4-1\"]\n",
"\n",
"def prompt(question):\n",
" return f\"\"\"\n",
" Answer the following question using the context below.\n",
" Question: {question}\n",
" Context:\n",
" \"\"\"\n",
"\n",
"questions = [\"What team won the game?\", \"What was score?\"]\n",
"\n",
"execute = lambda query: rag([(question, query, prompt(question), False) for question in questions], data)\n",
"\n",
"for query in [\"Red Sox - Blue Jays\", \"Phillies - Braves\", \"Dodgers - Giants\", \"Flyers - Lightning\"]:\n",
" print(\"----\", query, \"----\")\n",
" for answer in execute(query):\n",
" for answer in rag([f\"{query} {x}\" for x in questions], data):\n",
" print(answer)\n",
" print()"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"---- Red Sox - Blue Jays ----\n",
"('What team won the game?', 'Blue Jays')\n",
"('What was score?', '2-1')\n",
"\n",
"---- Phillies - Braves ----\n",
"('What team won the game?', 'Phillies')\n",
"('What was score?', '5-0')\n",
"\n",
"---- Dodgers - Giants ----\n",
"('What team won the game?', 'Giants')\n",
"('What was score?', '5-4')\n",
"\n",
"---- Flyers - Lightning ----\n",
"('What team won the game?', 'Flyers')\n",
"('What was score?', '4-1')\n",
"\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7AnPvSeM3N1Z"
},
"source": [
"This code runs a series of questions. First it runs an embeddings filtering query to find the most relevant text. For example, `Red Sox - Blue Jays` finds text related to those teams. Then `What team won the game?` and `What was the score?` are asked.\n",
"\n",
"This logic is the same logic found in Notebook 5 - Extractive QA with txtai but uses prompt-based QA vs extractive QA. "
],
"metadata": {
"id": "7AnPvSeM3N1Z"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Aj8GoDk331cS"
},
"source": [
"# Embeddings-guided and Prompt-driven Search\n",
"\n",
"Now for the fun stuff. Let's build an embeddings index for the `ag_news` dataset (a set of news stories from the mid 2000s). Then we'll use prompts to ask questions with embeddings results as the context."
],
"metadata": {
"id": "Aj8GoDk331cS"
}
]
},
{
"cell_type": "code",
"source": [
"from datasets import load_dataset\n",
"\n",
"dataset = load_dataset(\"ag_news\", split=\"train\")\n",
"\n",
"# List of all text elements\n",
"texts = dataset[\"text\"]\n",
"\n",
"# Create an embeddings index over the dataset\n",
"embeddings = Embeddings({\"path\": \"sentence-transformers/all-MiniLM-L6-v2\", \"content\": True})\n",
"embeddings.index((x, text, None) for x, text in enumerate(texts))\n",
"\n",
"# Create RAG instance\n",
"rag = RAG(embeddings, \"google/flan-t5-large\")"
],
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -200,40 +172,41 @@
"id": "yL716oEZ43t-",
"outputId": "23f4b0e7-a60a-4e89-fb57-06966e6612f8"
},
"execution_count": null,
"outputs": []
"outputs": [
],
"source": [
"from datasets import load_dataset\n",
"\n",
"dataset = load_dataset(\"ag_news\", split=\"train\")\n",
"\n",
"# Create an embeddings index over the dataset\n",
"embeddings = Embeddings(path=\"sentence-transformers/all-MiniLM-L6-v2\", content=True)\n",
"embeddings.index(dataset[\"text\"])\n",
"\n",
"# Create RAG instance\n",
"rag = RAG(embeddings, \"Qwen/Qwen3-4B-Instruct-2507\", template=\"\"\"\n",
" Answer the following question using the provided context.\n",
"\n",
" Question:\n",
" {question}\n",
"\n",
" Context:\n",
" {context}\n",
"\"\"\", output=\"flatten\")"
]
},
{
"cell_type": "markdown",
"source": [
"Now let's run a prompt-driven search!"
],
"metadata": {
"id": "Ifl8JwLDBL7k"
}
},
"source": [
"Now let's run a prompt-driven search!"
]
},
{
"cell_type": "code",
"source": [
"def prompt(question):\n",
" return f\"\"\"Answer the following question using only the context below. Say 'no answer' when the question can't be answered.\n",
"Question: {question}\n",
"Context: \"\"\"\n",
"\n",
"def search(query, question=None):\n",
" # Default question to query if empty\n",
" if not question:\n",
" question = query\n",
"\n",
" return rag([(\"answer\", query, prompt(question), False)])[0][1]\n",
"\n",
"question = \"Who won the 2004 presidential election?\"\n",
"answer = search(question)\n",
"print(question, answer)\n",
"\n",
"nquestion = \"Who did the candidate beat?\"\n",
"print(nquestion, search(f\"{question} {answer}. {nquestion}\"))"
],
"execution_count": 22,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -241,91 +214,52 @@
"id": "5O1WBJ8153Mo",
"outputId": "ddf09da2-7d4c-4fd3-b0da-df5631bacd13"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"Who won the 2004 presidential election? George W. Bush\n",
"Who did the candidate beat? John F. Kerry\n"
"Who won the 2004 presidential election? George W. Bush won the 2004 presidential election.\n",
"Who did the candidate beat? George W. Bush beat John F. Kerry in the 2004 presidential election.\n"
]
}
],
"source": [
"question = \"Who won the 2004 presidential election?\"\n",
"answer = rag(question)\n",
"print(question, answer)\n",
"\n",
"nquestion = \"Who did the candidate beat?\"\n",
"print(nquestion, rag(f\"{question} {answer}. {nquestion}\"))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "AhViFXH_BZSo"
},
"source": [
"And there are the answers. Let's unpack how this works.\n",
"\n",
"The first thing the RAG pipeline does is run an embeddings search to find the most relevant text within the index. A context string is then built using those search results.\n",
"\n",
"After that, a prompt is generated, run and the answer printed. Let's see what a full prompt looks like."
],
"metadata": {
"id": "AhViFXH_BZSo"
}
},
{
"cell_type": "code",
"source": [
"text = prompt(question)\n",
"text += \"\\n\" + \"\\n\".join(x[\"text\"]for x in embeddings.search(question))\n",
"print(text)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "h7BsoJC3CFOq",
"outputId": "44ae0dec-4f79-4d44-88f5-585e5eae9cb2"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Answer the following question using only the context below. Say 'no answer' when the question can't be answered.\n",
"Question: Who won the 2004 presidential election?\n",
"Context: \n",
"Right- and left-click politics The 2004 presidential race ended last week in a stunning defeat for Massachusetts Senator John F. Kerry, as incumbent President George W. Bush cruised to an easy victory.\n",
"2004 Presidential Endorsements (AP) AP - Newspaper endorsements in the 2004 presidential campaign between President Bush, a Republican, and Sen. John Kerry, a Democrat.\n",
"Presidential Campaign to Nov. 2, 2004 (Reuters) Reuters - The following diary of events\\leading up to the presidential election on Nov. 2.\n"
]
}
"After that, a prompt is generated, run and the answer printed."
]
},
{
"cell_type": "markdown",
"source": [
"The prompt has the information needed to determine the answers to the questions."
],
"metadata": {
"id": "4m9XketCty3m"
}
},
{
"cell_type": "markdown",
"id": "JtDcVPdOB0Rv"
},
"source": [
"# Additional examples\n",
"\n",
"Before moving on, a couple more example questions."
],
"metadata": {
"id": "JtDcVPdOB0Rv"
}
]
},
{
"cell_type": "code",
"source": [
"question = \"Who won the World Series in 2004?\"\n",
"answer = search(question)\n",
"print(question, answer)\n",
"\n",
"nquestion = \"Who did they beat?\"\n",
"print(nquestion, search(f\"{question} {answer}. {nquestion}\"))"
],
"execution_count": 23,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -333,23 +267,28 @@
"id": "0NNLBwC-83MM",
"outputId": "4b9fabd7-baf9-4f7d-bb8b-c9c60c5101e4"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"Who won the World Series in 2004? Boston\n",
"Who did they beat? St Louis\n"
"Who won the World Series in 2004? The Boston Red Sox won the World Series in 2004.\n",
"What team did the Red Sox beat in the World Series? The Boston Red Sox beat the St. Louis Cardinals in the World Series.\n"
]
}
],
"source": [
"question = \"Who won the World Series in 2004?\"\n",
"answer = rag(question)\n",
"print(question, answer)\n",
"\n",
"nquestion = \"What team did the Red Sox beat in the World Series?\"\n",
"print(nquestion, rag(f\"{question} {answer}. {nquestion}\"))"
]
},
{
"cell_type": "code",
"source": [
"search(\"Tell me something interesting?\")"
],
"execution_count": 29,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
@@ -358,43 +297,36 @@
"id": "1P0zqkTW9cZW",
"outputId": "4f2232db-761b-464f-b47d-6695c84ffb80"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'herrings communicate by farting'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
"'An interesting fact is that herrings communicate by farting—a quirky and unusual discovery that was honored with an Ig Nobel Prize for its oddball research.'"
]
},
"execution_count": 29,
"metadata": {},
"execution_count": 8
"output_type": "execute_result"
}
],
"source": [
"rag(\"Tell me something interesting\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ygFFcwWPGI9p"
},
"source": [
"Whhaaaattt??? Is this a model hallucination?\n",
"\n",
"Let's run an embeddings query and see if that text is in the results."
],
"metadata": {
"id": "ygFFcwWPGI9p"
}
]
},
{
"cell_type": "code",
"source": [
"answer = \"herrings communicate by farting\"\n",
"for x in embeddings.search(\"Tell me something interesting?\"):\n",
" if answer in x[\"text\"]:\n",
" start = x[\"text\"].find(answer)\n",
" print(x[\"text\"][start:start + len(answer)])"
],
"execution_count": 28,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -402,143 +334,68 @@
"id": "qZPhLqSxGMbK",
"outputId": "e3b2909a-1ee8-480f-afa3-201a8e27cb08"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"herrings communicate by farting\n"
]
}
],
"source": [
"answer = \"herrings communicate by farting\"\n",
"for x in embeddings.search(\"Tell me something interesting\"):\n",
" if answer in x[\"text\"]:\n",
" start = x[\"text\"].find(answer)\n",
" print(x[\"text\"][start:start + len(answer)])"
]
},
{
"cell_type": "markdown",
"source": [
"Sure enough it is. It appears that the FLAN-T5 model has a bit of an immature sense of humor 😃"
],
"metadata": {
"id": "IpgxMc1DZcds"
}
},
{
"cell_type": "markdown",
"source": [
"# External API Integration\n",
"\n",
"In addition to support for Hugging Face models, the RAG pipeline also supports custom question-answer models. This could be a call to the OpenAI API (GPT-3), Cohere API, Hugging Face API or using langchain to manage that. All that is needed is a Callable object or a function!\n",
"\n",
"Let's see an example that uses the Hugging Face API to answer questions. We'll use the original sports dataset to demonstrate."
],
"metadata": {
"id": "7bitjzeyYOqh"
}
},
{
"cell_type": "code",
"source": [
"import requests\n",
"\n",
"data = [\"Giants hit 3 HRs to down Dodgers\",\n",
" \"Giants 5 Dodgers 4 final\",\n",
" \"Dodgers drop Game 2 against the Giants, 5-4\",\n",
" \"Blue Jays beat Red Sox final score 2-1\",\n",
" \"Red Sox lost to the Blue Jays, 2-1\",\n",
" \"Blue Jays at Red Sox is over. Score: 2-1\",\n",
" \"Phillies win over the Braves, 5-0\",\n",
" \"Phillies 5 Braves 0 final\",\n",
" \"Final: Braves lose to the Phillies in the series opener, 5-0\",\n",
" \"Lightning goaltender pulled, lose to Flyers 4-1\",\n",
" \"Flyers 4 Lightning 1 final\",\n",
" \"Flyers win 4-1\"]\n",
"\n",
"def prompt(question):\n",
" return f\"\"\"\n",
" Answer the following question using the context below.\n",
" Question: {question}\n",
" Context:\n",
" \"\"\"\n",
"\n",
"# Submits a series of prompts to the Hugging Face API.\n",
"# This call can easily be switched to use the OpenAI API (GPT-3), Cohere API or a library like langchain.\n",
"def api(prompts):\n",
" response = requests.post(\"https://api-inference.huggingface.co/models/google/flan-t5-base\",\n",
" json={\"inputs\": prompts})\n",
"\n",
" return [x[\"generated_text\"] for x in response.json()]\n",
"\n",
"# Create embeddings model with content support\n",
"embeddings = Embeddings({\"path\": \"sentence-transformers/all-MiniLM-L6-v2\", \"content\": True})\n",
"\n",
"# Create RAG instance, submit prompts to the Hugging Face inference API\n",
"rag = RAG(embeddings, api)\n",
"\n",
"questions = [\"What team won the game?\", \"What was score?\"]\n",
"\n",
"execute = lambda query: rag([(question, query, prompt(question), False) for question in questions], data)\n",
"\n",
"for query in [\"Red Sox - Blue Jays\", \"Phillies - Braves\", \"Dodgers - Giants\", \"Flyers - Lightning\"]:\n",
" print(\"----\", query, \"----\")\n",
" for answer in execute(query):\n",
" print(answer)\n",
" print()\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "yYAa9N7EYm7E",
"outputId": "72208327-bfb7-466f-c664-3630f207b6dd"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"---- Red Sox - Blue Jays ----\n",
"('What team won the game?', 'Blue Jays')\n",
"('What was score?', '2-1')\n",
"\n",
"---- Phillies - Braves ----\n",
"('What team won the game?', 'Phillies')\n",
"('What was score?', '5-0')\n",
"\n",
"---- Dodgers - Giants ----\n",
"('What team won the game?', 'Giants')\n",
"('What was score?', '5-4')\n",
"\n",
"---- Flyers - Lightning ----\n",
"('What team won the game?', 'Flyers')\n",
"('What was score?', '4-1')\n",
"\n"
]
}
"source": [
"Sure enough it is 😃"
]
},
{
"cell_type": "markdown",
"source": [
"Everything matches with first example above in [Create Embeddings and RAG instances](#Create-Embeddings-and-RAG-instances) except the prompts are run as an external API call.\n",
"\n",
"The Embeddings instance can also swap out the vectorization, database and vector store components with external API services. Check out the [txtai documentation](https://neuml.github.io/txtai/embeddings/configuration/) documentation for more information.\n",
"\n"
],
"metadata": {
"id": "Xh8UhC3NdsGf"
}
},
{
"cell_type": "markdown",
"id": "KqfvCXp2B3li"
},
"source": [
"# Wrapping up\n",
"\n",
"This notebook covered how to run embeddings-guided and prompt-driven search with LLMs. This functionality is a major step forward towards `Generative Semantic Search` for txtai. More to come, stay tuned!"
],
"metadata": {
"id": "KqfvCXp2B3li"
}
]
}
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "local",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.19"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+179 -169
View File
@@ -1,17 +1,4 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "markdown",
@@ -41,15 +28,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "LPQTb25tASIG"
},
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[api]"
],
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
@@ -61,36 +48,46 @@
"\n",
"First, we'll look at building a workflow with a series of model prompts. This workflow creates a conditional translation using a statement and target language. Another task reads that output text and detects the language.\n",
"\n",
"This workflow uses a sequences pipeline. The sequences pipeline loads a Hugging Face sequence to sequence model for inference, in this case [FLAN-T5](https://huggingface.co/google/flan-t5-base). The sequences pipeline takes a prompt as input and outputs the model inference result.\n",
"This workflow uses a LLM pipeline. The LLM pipeline loads a local model for inference, in this case [Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507). The [LLM pipeline](https://neuml.github.io/txtai/pipeline/llm/llm) supports local transformers models, llama.cpp models and LLM APIs such as Ollama, vLLM, OpenAI, Claude etc. \n",
"\n",
"It's important to note that a pipeline is simply a callable function. It can easily be replaced with a call to an external API."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "OUc9gqTyAYnm",
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "OUc9gqTyAYnm",
"outputId": "83300311-736c-47c8-bc16-ec0303274054"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['French', 'German']\n"
]
}
],
"source": [
"from txtai.pipeline import Sequences\n",
"from txtai.workflow import Workflow, TemplateTask\n",
"from txtai import LLM, Workflow\n",
"from txtai.workflow import TemplateTask\n",
"\n",
"# Create sequences pipeline\n",
"sequences = Sequences(\"google/flan-t5-large\")\n",
"# Create LLM\n",
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")\n",
"\n",
"# Define workflow or chaining of tasks together.\n",
"workflow = Workflow([\n",
" TemplateTask(\n",
" template=\"Translate '{statement}' to {language} if it's English\",\n",
" action=sequences\n",
" template=\"Translate text '{statement}' to {language} if the text is English, otherwise keep the original text\",\n",
" action=llm\n",
" ),\n",
" TemplateTask(\n",
" template=\"What language is the following text? {text}\",\n",
" action=sequences\n",
" template=\"What language is the following text. Only print the answer? {text}\",\n",
" action=llm\n",
" )\n",
"])\n",
"\n",
@@ -100,20 +97,13 @@
"]\n",
"\n",
"print(list(workflow(inputs)))"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"['French', 'German']\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_zz4Do8BV-Lk"
},
"source": [
"Let's recap what happened here. The first workflow task conditionally translates text to a language if it's English.\n",
"\n",
@@ -122,40 +112,22 @@
"The second statement is German, so it's not converted to French.\n",
"\n",
"The next step asks the model what the language is and it correctly prints `French` and `German`."
],
"metadata": {
"id": "_zz4Do8BV-Lk"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "iXDAKP4CX0W9"
},
"source": [
"# Prompt Workflow as YAML\n",
"\n",
"The same workflow above can be created with YAML configuration."
],
"metadata": {
"id": "iXDAKP4CX0W9"
}
]
},
{
"cell_type": "code",
"source": [
"%%writefile workflow.yml\n",
"\n",
"sequences:\n",
" path: google/flan-t5-large\n",
"\n",
"workflow:\n",
" chain:\n",
" tasks:\n",
" - task: template\n",
" template: Translate '{statement}' to {language} if it's English\n",
" action: sequences\n",
" - task: template\n",
" template: What language is the following text? {text}\n",
" action: sequences"
],
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -163,25 +135,35 @@
"id": "GwV5A9xRYtYs",
"outputId": "ffe6ee65-95a7-46c6-e6b9-5324eab26ca8"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"Writing workflow.yml\n"
]
}
],
"source": [
"%%writefile workflow.yml\n",
"\n",
"llm:\n",
" path: Qwen/Qwen3-4B-Instruct-2507\n",
"\n",
"workflow:\n",
" chain:\n",
" tasks:\n",
" - task: template\n",
" template: Translate text '{statement}' to {language} if the text is English, otherwise keep the original text\n",
" action: llm\n",
" - task: template\n",
" template: What language is the following text. Only print the answer? {text}\n",
" action: llm"
]
},
{
"cell_type": "code",
"source": [
"from txtai import Application\n",
"\n",
"app = Application(\"workflow.yml\")\n",
"print(list(app.workflow(\"chain\", inputs)))"
],
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -189,58 +171,58 @@
"id": "dr7Lv5S5X98e",
"outputId": "d6ac0427-671d-4525-aa21-664430109af3"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"['French', 'German']\n"
]
}
],
"source": [
"from txtai import Application\n",
"\n",
"app = Application(\"workflow.yml\")\n",
"print(list(app.workflow(\"chain\", inputs)))"
]
},
{
"cell_type": "markdown",
"source": [
"As expected, the same result! This is a matter of preference on how you want to create a workflow. One advantage of YAML workflows is that an API can easily be created from the workflow file."
],
"metadata": {
"id": "EGqiV45fYVse"
}
},
"source": [
"As expected, the same result! This is a matter of preference on how you want to create a workflow. One advantage of YAML workflows is that an API can easily be created from the workflow file."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9PqMU0bNYinf"
},
"source": [
"# Prompt Workflow via an API call\n",
"\n",
"Let's say you want the workflow to be available via an API call. Well good news, txtai has a built in API mechanism using FastAPI. "
],
"metadata": {
"id": "9PqMU0bNYinf"
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vDxQj1ZIYsz3"
},
"outputs": [],
"source": [
"# Start an API service\n",
"!CONFIG=workflow.yml nohup uvicorn \"txtai.api:app\" &> api.log &\n",
"!sleep 60"
],
"metadata": {
"id": "vDxQj1ZIYsz3"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"source": [
"import requests\n",
"\n",
"# Run API request\n",
"requests.post(\"http://localhost:8000/workflow\", json={\"name\": \"chain\", \"elements\": inputs}).json()"
],
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -248,31 +230,53 @@
"id": "R1o08SVtZW7h",
"outputId": "99875acd-18a8-4c2c-ead3-cb6975a4b2d2"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"['French', 'German']"
]
},
"execution_count": 3,
"metadata": {},
"execution_count": 5
"output_type": "execute_result"
}
],
"source": [
"import requests\n",
"\n",
"# Run API request\n",
"requests.post(\"http://localhost:8000/workflow\", json={\"name\": \"chain\", \"elements\": inputs}).json()"
]
},
{
"cell_type": "markdown",
"source": [
"Just like the previous steps, except through an API call. Let's run via cURL for good measure."
],
"metadata": {
"id": "B88mCrGFl5W-"
}
},
"source": [
"Just like the previous steps, except through an API call. Let's run via cURL for good measure."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hRUyh0cQl_P2",
"outputId": "9db8481d-0b6e-4a31-bdf6-5443df5f768a"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"French\",\"German\"]"
]
}
],
"source": [
"%%bash\n",
"\n",
@@ -287,51 +291,51 @@
" ]\n",
"}\n",
"EOF"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hRUyh0cQl_P2",
"outputId": "9db8481d-0b6e-4a31-bdf6-5443df5f768a"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[\"French\",\"German\"]"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "W0zL93WPoaCo"
},
"source": [
"One last time, the same output is shown.\n",
"\n",
"If your primary development environment isn't Python, txtai does have API bindings for [JavaScript](https://github.com/neuml/txtai.js), [Rust](https://github.com/neuml/txtai.rs), [Go](https://github.com/neuml/txtai.go) and [Java](https://github.com/neuml/txtai.java).\n",
"\n",
"More information on the API is available [here](https://neuml.github.io/txtai/api/)."
],
"metadata": {
"id": "W0zL93WPoaCo"
}
]
},
{
"cell_type": "markdown",
"source": [
"# Conversational chain\n",
"\n",
"Conversational search is another big area of focus in 2023. [txtchat](https://github.com/neuml/txtchat) is a framework for building conversational search applications. It relies heavily on txtai. Let's see a conversational example."
],
"metadata": {
"id": "q9WiFG6fpzw5"
}
},
"source": [
"# Chat with your data\n",
"\n",
"\"Chat with your data\" is a popular entry point into the AI space. Let's run an example."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "rM3Y551LqF-J",
"outputId": "85623785-c15f-4996-9460-0644f69cf5bf"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Writing search.yml\n"
]
}
],
"source": [
"%%writefile search.yml\n",
"\n",
@@ -341,48 +345,27 @@
" container: neuml/txtai-intro\n",
"\n",
"rag:\n",
" path: google/flan-t5-large\n",
" path: Qwen/Qwen3-4B-Instruct-2507\n",
" output: reference\n",
" template: |\n",
" Answer the following question using only the context below.\n",
"\n",
" Question: {question}\n",
" Context: {context}\n",
"\n",
"workflow:\n",
" search:\n",
" tasks:\n",
" - task: rag\n",
" template: |\n",
" Answer the following question using only the context below. Give a detailed answer.\n",
" Say 'I don't have data on that' when the question can't be answered.\n",
" Question: {text}\n",
" Context: \n",
" action: rag\n",
" - action: rag\n",
" - task: template\n",
" template: \"{answer}\\n\\nReference: {reference}\"\n",
" rules:\n",
" answer: I don't have data on that"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "rM3Y551LqF-J",
"outputId": "85623785-c15f-4996-9460-0644f69cf5bf"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Overwriting search.yml\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"app = Application(\"search.yml\")\n",
"print(list(app.workflow(\"search\", [\"Tell me something about North America\"])))"
],
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -390,40 +373,67 @@
"id": "1Elb8JANqpwX",
"outputId": "b1f1ffa1-6c47-4d90-b6f1-8098d4dc45f8"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"[\"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg\\n\\nReference: 1\"]\n"
"[\"Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg.\\n\\nReference: 1\"]\n"
]
}
],
"source": [
"app = Application(\"search.yml\")\n",
"print(list(app.workflow(\"search\", [\"Find something about North America\"])))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4r49V4c9s5nf"
},
"source": [
"The first thing the code above does is run an embeddings search to build a conversational context. That context is then used to build a prompt and inference is run against the LLM. \n",
"\n",
"The next task formats the outputs with a reference to the best matching record. In this case, it's only an id of 1. But this can be much more useful if the id is a URL or there is logic to format the id back to a unique reference string.\n",
"\n",
"The [txtchat](https://github.com/neuml/txtchat) project has much more on this, check it out!"
],
"metadata": {
"id": "4r49V4c9s5nf"
}
"The next task formats the outputs with a reference to the best matching record. In this case, it's only an id of 1. But this can be much more useful if the id is a URL or there is logic to format the id back to a unique reference string."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KqfvCXp2B3li"
},
"source": [
"# Wrapping up\n",
"\n",
"This notebook covered how to build prompt templates and task chains through a series of results. txtai has long had a robust and efficient workflow framework for connecting models together. This can be small and simple models and/or prompting with large models. Go ahead and give it a try!"
],
"metadata": {
"id": "KqfvCXp2B3li"
}
]
}
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "local",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.19"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -428,7 +428,7 @@
"source": [
"import txtai\n",
"\n",
"# Creat embeddings\n",
"# Create embeddings\n",
"embeddings = txtai.Embeddings(\n",
" keyword=True,\n",
" content=\"postgresql+psycopg2://postgres:postgres@localhost/postgres\",\n",
@@ -799,4 +799,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
+1 -2
View File
@@ -78,8 +78,7 @@
"\n",
"# LLM pipeline\n",
"llm:\n",
" path: google/flan-t5-large\n",
" torch_dtype: torch.bfloat16"
" path: Qwen/Qwen3-4B-Instruct-2507"
],
"metadata": {
"colab": {
+245 -248
View File
@@ -1,61 +1,45 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "VGeVB8M41jqW"
},
"source": [
"# Build RAG pipelines with txtai\n",
"\n",
"Large Language Models (LLMs) have completely dominated the AI and machine learning space in 2023. The results have been amazing and the public imagination is almost endless.\n",
"Large Language Models (LLMs) have completely dominated the tech space in recent years. The results have been amazing and the public imagination is almost endless.\n",
"\n",
"While LLMs have been impressive, they are not problem free. The biggest challenge is with hallucinations. Hallucinations is the term for when a LLM generates output that is factually incorrect. The alarming part of this is that on a cursory glance, it actually sounds like good content. The default behavior of LLMs is to produce plausible answers even when no plausible answer exists. LLMs are not great at saying I don't know.\n",
"\n",
"Retrieval augmented generation (RAG) helps reduce the risk of hallucinations by limiting the context in which a LLM can generate answers. This is typically done with a vector search query that hydrates a prompt with a relevant context. RAG is one of the most practical and production-ready use cases for *Generative AI*. It's so popular now, that some are creating their entire companies around it.\n",
"\n",
"[txtai](https://github.com/neuml/txtai) has long had question-answering pipelines, which employ the same process of retrieving a relevant context. LLMs are now the preferred approach for analyzing that context and RAG pipelines are one of the main features of txtai. One of the other main features of txtai is that it's a vector database! You can build your prompts and limit your context all with one library. Hence the phrase *all-in-one embeddings database*.\n",
"[txtai](https://github.com/neuml/txtai) has long had question-answering pipelines, which employ the same process of retrieving a relevant context. LLMs are now the preferred approach for analyzing that context and RAG pipelines are one of the main features of txtai. One of the other main features of txtai is that it's a vector database! You can build your prompts and limit your context all with one library. Hence the phrase *all-in-one AI framework*.\n",
"\n",
"This notebook shows how to build RAG pipelines with txtai."
],
"metadata": {
"id": "VGeVB8M41jqW"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ZQrHIw351lwE"
},
"source": [
"# Install dependencies\n",
"\n",
"Install `txtai` and all dependencies. Since this notebook is using optional pipelines, we need to install the pipeline extras package."
],
"metadata": {
"id": "ZQrHIw351lwE"
}
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"id": "R0AqRP7v1hdr"
},
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline] autoawq\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline]\n",
"\n",
"# Get test data\n",
"!wget -N https://github.com/neuml/txtai/releases/download/v6.2.0/tests.tar.gz\n",
@@ -68,50 +52,43 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "xmPN8RDF1pXd"
},
"source": [
"# Start with the basics\n",
"\n",
"Let's jump right in and start with a simple LLM pipeline. The [LLM pipeline](https://neuml.github.io/txtai/pipeline/text/llm/) supports loading local LLM models from the [Hugging Face Hub](https://huggingface.co/models).\n",
"Let's jump right in and start with a simple LLM pipeline. The [LLM pipeline](https://neuml.github.io/txtai/pipeline/text/llm/) supports local LLM models via [Hugging Face Transformers](https://github.com/huggingface/transformers) and [llama.cpp](https://github.com/abetlen/llama-cpp-python).\n",
"\n",
"For those using LLM API services (OpenAI, Cohere, etc), this call can easily be replaced with an API call."
],
"metadata": {
"id": "xmPN8RDF1pXd"
}
"The LLM pipeline also supports [API services (i.e. OpenAI, Claude, Bedrock etc) via LiteLLM](https://github.com/BerriAI/litellm). The LLM pipeline automatically detects the underlying LLM framework from the `path` parameter.\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "XZ7vPBIs1rGZ"
},
"outputs": [],
"source": [
"from txtai import LLM\n",
"\n",
"# Create LLM\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\")"
],
"metadata": {
"id": "XZ7vPBIs1rGZ"
},
"execution_count": 21,
"outputs": []
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")"
]
},
{
"cell_type": "markdown",
"source": [
"Next, we'll load a document to query. The [Textractor pipeline](https://neuml.github.io/txtai/pipeline/data/textractor/) has support for extracting text from common document formats (docx, pdf, xlsx)."
],
"metadata": {
"id": "9rmTWMxAH3Vx"
}
},
"source": [
"Next, we'll load a document to query. The [Textractor pipeline](https://neuml.github.io/txtai/pipeline/data/textractor/) has support for extracting text from common document formats (docx, pdf, xlsx, web)."
]
},
{
"cell_type": "code",
"source": [
"from txtai.pipeline import Textractor\n",
"\n",
"# Create Textractor\n",
"textractor = Textractor()\n",
"text = textractor(\"txtai/document.docx\")\n",
"print(text)"
],
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -119,24 +96,24 @@
"id": "nifStGtOHuyc",
"outputId": "5a4010e0-75f9-4095-a24c-cd4c859847d0"
},
"execution_count": 22,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"txtai – the all-in-one embeddings database\n",
"# txtai – the all-in-one embeddings database\n",
"txtai is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"Summary of txtai features:\n",
"· Vector search with SQL, object storage, topic modeling\n",
"· Create embeddings for text, documents, audio, images and video\n",
"· Pipelines powered by language models that run LLM prompts\n",
"· Workflows to join pipelines together and aggregate business logic\n",
"· Build with Python or YAML. API bindings available for JavaScript, Java, Rust and Go.\n",
"· Run local or scale out with container orchestration\n",
"· *Vector search* with SQL, object storage, topic modeling\n",
"· Create *embeddings* for text, documents, audio, images and video\n",
"· *Pipelines* powered by language models that run LLM prompts\n",
"· *Workflows* to join pipelines together and aggregate business logic\n",
"· Build with *Python* or *YAML* . API bindings available for JavaScript, Java, Rust and Go.\n",
"· *Run local or scale out with container orchestration* \n",
"\n",
"Examples\n",
"\n",
"## Examples\n",
"List of example notebooks.\n",
"|Notebook|Description|\n",
"|---|---|\n",
@@ -145,16 +122,17 @@
"|Build a QA database|Question matching with semantic search|\n",
"|Semantic Graphs|Explore topics, data connectivity and run network analysis|\n",
"\n",
"Install\n",
"## Install\n",
"The easiest way to install is via pip and PyPI\n",
"pip install txtai\n",
"Python 3.8+ is supported. Using a Python virtual environment is recommended.\n",
"Python 3.11+ is supported. Using a Python virtual environment is **recommended** .\n",
"See the detailed install instructions for more information covering optional dependencies, environment specific prerequisites, installing from source, conda support and how to run with containers.\n",
"\n",
"\n",
"\n",
"\n",
"Model guide\n",
"\n",
"## Model guide\n",
"The following shows a list of suggested models.\n",
"|Component|Model(s)|\n",
"|---|---|\n",
@@ -171,35 +149,28 @@
"|Translation|OPUS Model Series|\n"
]
}
],
"source": [
"from txtai import Textractor\n",
"\n",
"# Create Textractor\n",
"textractor = Textractor()\n",
"text = textractor(\"txtai/document.docx\")\n",
"print(text)"
]
},
{
"cell_type": "markdown",
"source": [
"Now we'll define a simple LLM pipeline. It takes a question and context (which in this case is the whole file), creates a prompt and runs it with the LLM."
],
"metadata": {
"id": "2jkamwgdIgEp"
}
},
"source": [
"Now we'll define a simple LLM pipeline. It takes a question and context (which in this case is the whole file), creates a prompt and runs it with the LLM."
]
},
{
"cell_type": "code",
"source": [
"def execute(question, text):\n",
" prompt = f\"\"\"<|im_start|>system\n",
" You are a friendly assistant. You answer questions from users.<|im_end|>\n",
" <|im_start|>user\n",
" Answer the following question using only the context below. Only include information specifically discussed.\n",
"\n",
" question: {question}\n",
" context: {text} <|im_end|>\n",
" <|im_start|>assistant\n",
" \"\"\"\n",
"\n",
" return llm(prompt, maxlength=4096, pad_token_id=32000)\n",
"\n",
"execute(\"Tell me about txtai in one sentence\", text)"
],
"execution_count": 18,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
@@ -208,28 +179,36 @@
"id": "9HU6C0OIIAKn",
"outputId": "f9d556c4-cd7a-4774-ef62-1f3fff90aa47"
},
"execution_count": 23,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'Txtai is an all-in-one embeddings database for semantic search, LLM orchestration, and language model workflows, offering features such as vector search, pipeline creation, workflow management, and API bindings for various programming languages.'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
"'txtai is an all-in-one embeddings database that supports semantic search, LLM orchestration, and language model workflows with features like vector search, embeddings for text, audio, images, and video, pipelines powered by language models, and scalable workflows available via Python or YAML with API bindings for multiple languages.'"
]
},
"execution_count": 18,
"metadata": {},
"execution_count": 23
"output_type": "execute_result"
}
],
"source": [
"def execute(question, text):\n",
" return llm([\n",
" {\"role\": \"system\", \"content\": \"You are a friendly assistant. You answer questions from users.\"},\n",
" {\"role\": \"user\", \"content\": f\"\"\"\n",
" Answer the following question using only the context below. Only include information specifically discussed.\n",
"\n",
" question: {question}\n",
" context: {text} \n",
" \"\"\"}\n",
" ], maxlength=4096)\n",
"\n",
"execute(\"Tell me about txtai in one sentence\", text)"
]
},
{
"cell_type": "code",
"source": [
"execute(\"What model does txtai recommend for transcription?\", text)"
],
"execution_count": 19,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
@@ -238,28 +217,25 @@
"id": "xxF7ajCPJP5_",
"outputId": "0e6f6dbb-c784-4841-fe3f-82754ef478eb"
},
"execution_count": 24,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'The model that txtai recommends for transcription is Whisper.'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
"'txtai recommends using Whisper for transcription.'"
]
},
"execution_count": 19,
"metadata": {},
"execution_count": 24
"output_type": "execute_result"
}
],
"source": [
"execute(\"What model does txtai recommend for transcription?\", text)"
]
},
{
"cell_type": "code",
"source": [
"execute(\"I don't know anything about txtai, what would be the best thing to read?\", text)"
],
"execution_count": 20,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
@@ -268,36 +244,38 @@
"id": "AKmmTqsnJa5X",
"outputId": "834bf3ee-b7ed-4e38-e2ef-d5950f99ed9a"
},
"execution_count": 25,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'The best thing to read to learn about txtai is the \"Introducing txtai\" notebook, which provides an overview of the functionality provided by txtai. This notebook covers various features such as vector search with SQL, object storage, topic modeling, creating embeddings for text, documents, audio, images, and video, and running language model workflows. Additionally, you can explore other example notebooks like \"Similarity search with images,\" \"Build a QA database,\" and \"Semantic Graphs\" to learn more about specific use cases and features. To install txtai, use pip and PyPI with Python 3.8+, and follow the detailed install instructions for more information on optional dependencies and environment-specific prerequisites.'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
"'The best thing to read if you don\\'t know anything about txtai would be the \"Introducing txtai\" notebook, as it provides an overview of the functionality offered by txtai.'"
]
},
"execution_count": 20,
"metadata": {},
"execution_count": 25
"output_type": "execute_result"
}
],
"source": [
"execute(\"I don't know anything about txtai, what would be the best thing to read?\", text)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WaVeEHrIMpFr"
},
"source": [
"If this is the first time you've seen *Generative AI*, then these statements are 🤯. Even if you've been in the space a while, it's still amazing how much a language model can understand and the high level of quality in it's answers.\n",
"\n",
"While this use case is fun, lets try to scale it to a larger set of documents."
],
"metadata": {
"id": "WaVeEHrIMpFr"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "viVVft59NbKv"
},
"source": [
"# Build a RAG pipeline with vector search\n",
"\n",
@@ -308,13 +286,30 @@
"Typically, this candidate query uses vector search but it can be anything that runs a search and returns results. In fact, many complex production systems have customized retrieval pipelines that feed a context into LLM prompts.\n",
"\n",
"The first step in building our RAG pipeline is creating the knowledge store. In this case, it's a vector database of file content. The files will be split into paragraphs with each paragraph stored as a separate row."
],
"metadata": {
"id": "viVVft59NbKv"
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ipmsmtN1NahT",
"outputId": "64733e1f-fb7b-4a2d-bf02-8930478a8ee8"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Indexing txtai/article.pdf\n",
"Indexing txtai/document.docx\n",
"Indexing txtai/document.pdf\n",
"Indexing txtai/spreadsheet.xlsx\n"
]
}
],
"source": [
"import os\n",
"\n",
@@ -336,39 +331,40 @@
"# Vector Database\n",
"embeddings = Embeddings(content=True)\n",
"embeddings.index(stream(\"txtai\"))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ipmsmtN1NahT",
"outputId": "64733e1f-fb7b-4a2d-bf02-8930478a8ee8"
},
"execution_count": 26,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Indexing txtai/article.pdf\n",
"Indexing txtai/document.docx\n",
"Indexing txtai/document.pdf\n",
"Indexing txtai/spreadsheet.xlsx\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"The next step is defining the RAG pipeline. This pipeline takes the input question, runs a vector search and builds a context using the search results. The context is then inserted into a prompt template and run with the LLM."
],
"metadata": {
"id": "ASlmAaR3nBPN"
}
},
"source": [
"The next step is defining the RAG pipeline. This pipeline takes the input question, runs a vector search and builds a context using the search results. The context is then inserted into a prompt template and run with the LLM."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 39
},
"id": "_-9SW6r4P5ha",
"outputId": "6a7bcd69-bcd0-4f6e-81c1-e32c323b3ffb"
},
"outputs": [
{
"data": {
"text/plain": [
"'txtai recommends using BLIP for image captioning.'"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def context(question):\n",
" context = \"\\n\".join(x[\"text\"] for x in embeddings.search(question))\n",
@@ -378,38 +374,11 @@
" return execute(question, context(question))\n",
"\n",
"rag(\"What model does txtai recommend for image captioning?\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 39
},
"id": "_-9SW6r4P5ha",
"outputId": "6a7bcd69-bcd0-4f6e-81c1-e32c323b3ffb"
},
"execution_count": 27,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'Based on the provided context, txtai recommends the model \"BLIP\" for image captioning.'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 27
}
]
},
{
"cell_type": "code",
"source": [
"result = rag(\"When was the BLIP model added for image captioning?\")\n",
"print(result)"
],
"execution_count": 24,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -417,47 +386,47 @@
"id": "NbQhSunPQtB0",
"outputId": "de0caf04-4cdb-48e8-aadf-37283be9909a"
},
"execution_count": 28,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"The BLIP model was added for image captioning on 2022-03-17.\n"
]
}
],
"source": [
"result = rag(\"When was the BLIP model added for image captioning?\")\n",
"print(result)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "D6HW-3GtnTFl"
},
"source": [
"As we can see, the result is similar to what we had before without vector search. The difference is that we only used a relevant portion of the documents to generate the answer.\n",
"\n",
"As we discussed before, this is important when dealing with large volumes of data. Not all of the data can be added to a LLM prompt. Additionally, having only the most relevant context helps the LLM generate higher quality answers."
],
"metadata": {
"id": "D6HW-3GtnTFl"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "FZ-yPC-xiUqa"
},
"source": [
"# Citations for LLMs\n",
"\n",
"A healthy level of skepticism should be applied to answers generated by AI. We're far from the day where we can blindly trust answers from an AI model.\n",
"\n",
"txtai has a couple approaches for generating citations. The basic approach is to take the answer and search the vector database for the closest match."
],
"metadata": {
"id": "FZ-yPC-xiUqa"
}
]
},
{
"cell_type": "code",
"source": [
"for x in embeddings.search(result):\n",
" print(x[\"text\"])"
],
"execution_count": 25,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -465,16 +434,15 @@
"id": "obttSg_dSFT5",
"outputId": "c7ae7675-6959-4bcb-ad06-065ea8609c31"
},
"execution_count": 29,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"E5-base-v2\n",
"Image Captions BLIP\n",
"Labels - Zero Shot BART-Large-MNLI\n",
"Model Guide\n",
"# Model Guide\n",
"|Component |Model(s)|Date Added|\n",
"|---|---|---|\n",
"|Embeddings |all-MiniLM-L6-v2|2022-04-15|\n",
@@ -486,66 +454,65 @@
"|Transcription |Whisper|2022-08-01|\n",
"|Translation |OPUS Model Series|2021-04-06|\n",
"&\"Times New Roman,Regular\"&12&A\n",
"Notebook Description\n",
"Introducing txtai Overview of the functionality provided by txtai\n",
"Similarity search with \n",
"images Embed images and text into the same space for search\n"
"## Model guide\n",
"The following shows a list of suggested models.\n",
"|Component|Model(s)|\n",
"|---|---|\n",
"|Embeddings|all-MiniLM-L6-v2|\n",
"||E5-base-v2|\n",
"|Image Captions|BLIP|\n",
"|Labels - Zero Shot|BART-Large-MNLI|\n",
"|Labels - Fixed|Fine-tune with training pipeline|\n",
"|Large Language Model (LLM)|Flan T5 XL|\n",
"||Mistral 7B OpenOrca|\n",
"|Summarization|DistilBART|\n",
"|Text-to-Speech|ESPnet JETS|\n",
"|Transcription|Whisper|\n",
"|Translation|OPUS Model Series|\n"
]
}
],
"source": [
"for x in embeddings.search(result):\n",
" print(x[\"text\"])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "MDcB7GCWY6TO"
},
"source": [
"While the basic approach above works in this case, txtai has a more robust pipeline to handle citations and references.\n",
"\n",
"The RAG pipeline is defined below. A RAG pipeline works in the same way as a LLM + Vector Search pipeline, except it has special logic for generating citations. This pipeline takes the answers and compares it to the context passed to the LLM to determine the most likely reference."
],
"metadata": {
"id": "MDcB7GCWY6TO"
}
]
},
{
"cell_type": "code",
"source": [
"from txtai import RAG\n",
"\n",
"# RAG prompt\n",
"def prompt(question):\n",
" return [{\n",
" \"query\": question,\n",
" \"question\": f\"\"\"\n",
"Answer the following question using only the context below. Only include information specifically discussed.\n",
"\n",
"question: {question}\n",
"context:\n",
"\"\"\"\n",
"}]\n",
"\n",
"# Create LLM with system prompt template\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\", template=\"\"\"<|im_start|>system\n",
"You are a friendly assistant. You answer questions from users.<|im_end|>\n",
"<|im_start|>user\n",
"{text} <|im_end|>\n",
"<|im_start|>assistant\n",
"\"\"\")\n",
"\n",
"# Create RAG instance\n",
"rag = RAG(embeddings, llm, output=\"reference\")"
],
"execution_count": 26,
"metadata": {
"id": "Lm6gg85_Y7ot"
},
"execution_count": null,
"outputs": []
"outputs": [],
"source": [
"from txtai import RAG\n",
"\n",
"# Create the RAG pipeline\n",
"rag = RAG(embeddings, \"Qwen/Qwen3-4B-Instruct-2507\", template=\"\"\"\n",
" Answer the following question using the provided context.\n",
"\n",
" Question:\n",
" {question}\n",
"\n",
" Context:\n",
" {context}\n",
"\"\"\", output=\"reference\")"
]
},
{
"cell_type": "code",
"source": [
"result = rag(prompt(\"What version of Python is supported?\"), maxlength=4096, pad_token_id=32000)[0]\n",
"print(\"ANSWER:\", result[\"answer\"])\n",
"print(\"CITATION:\", embeddings.search(\"select id, text from txtai where id = :id\", limit=1, parameters={\"id\": result[\"reference\"]}))"
],
"execution_count": 27,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
@@ -553,29 +520,36 @@
"id": "4pOfE5paZatH",
"outputId": "2bed2de5-22ff-4f7b-dba5-41b8e4cc6c75"
},
"execution_count": 31,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"ANSWER: Python 3.8+ is supported. Using a Python virtual environment is recommended. The easiest way to install is via pip and PyPI.\n",
"CITATION: [{'id': '24', 'text': 'Python 3.8+ is supported. Using a Python virtual environment is recommended.'}]\n"
"ANSWER: Python 3.11 and later versions (Python 3.11+) are supported.\n",
"CITATION: [{'id': '24', 'text': 'Python 3.11+ is supported. Using a Python virtual environment is recommended.'}]\n"
]
}
],
"source": [
"result = rag(\"What version of Python is supported?\", maxlength=4096)\n",
"print(\"ANSWER:\", result[\"answer\"])\n",
"print(\"CITATION:\", embeddings.search(\"select id, text from txtai where id = :id\", limit=1, parameters={\"id\": result[\"reference\"]}))"
]
},
{
"cell_type": "markdown",
"source": [
"And as we can see, not only is the answer to the statement shown, the RAG pipeline also provides a citation. This step is crucial in any line of work where answers must be verified (which is most lines of work)."
],
"metadata": {
"id": "vHdE2Q59jNnF"
}
},
"source": [
"And as we can see, not only is the answer to the statement shown, the RAG pipeline also provides a citation. This step is crucial in any line of work where answers must be verified (which is most lines of work)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "oPwgCgBc2Er2"
},
"source": [
"# Wrapping up\n",
"\n",
@@ -583,13 +557,36 @@
"\n",
"The advantages of building RAG pipelines with txtai are:\n",
"\n",
"- **All-in-one database** - one library can handle LLM inference and vector search retrieval\n",
"- **All-in-one AI framework** - one library can handle LLM inference and vector search retrieval\n",
"- **Generating citations** - generating answers is useful but referencing where those answers came from is crucial in gaining the trust of users\n",
"- **Simple yet powerful** - building pipelines can be done in a small amount of Python. Options are available to build pipelines in YAML and/or run through the API"
],
"metadata": {
"id": "oPwgCgBc2Er2"
}
]
}
]
],
"metadata": {
"accelerator": "GPU",
"colab": {
"gpuType": "T4",
"provenance": []
},
"kernelspec": {
"display_name": "local",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.19"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+1 -1
View File
@@ -90,7 +90,7 @@
"embeddings.index(data)\n",
"\n",
"# Create LLM with llama.cpp - GGUF file is automatically downloaded\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-GGUF/mistral-7b-openorca.Q4_K_M.gguf\", verbose=True)\n",
"llm = LLM(\"unsloth/Qwen3-4B-Instruct-2507-GGUF/Qwen3-4B-Instruct-2507-Q4_K_M.gguf\", verbose=True)\n",
"\n",
"template = \"\"\"<|im_start|>system\n",
"You are a friendly assistant. You answer questions from users.<|im_end|>\n",
@@ -19,7 +19,7 @@
"source": [
"# API Authorization and Authentication\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows. txtai can run in Python, with YAML configuration and through an API service.\n",
"txtai can run in Python, with YAML configuration and through an API service.\n",
"\n",
"The default API service implementation runs without any security. This may be OK for a local prototype or if it's run on a small internal network. But in most cases, additional security measures should be taken.\n",
"\n",
@@ -8,8 +8,6 @@
"source": [
"# Generate knowledge with Semantic Graphs and RAG\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"Embeddings databases are a union of vector indexes (sparse and dense), graph networks and relational databases. This enables vector search with SQL, topic modeling, retrieval augmented generation and more.\n",
"\n",
"Semantic graphs were introduced in late 2022 with txtai 5.0, right before the start of the LLM era. This notebook picks back up where that work left off, opening a new frontier in semantic graph integration."
@@ -35,7 +33,7 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[graph] autoawq"
"!pip install git+https://github.com/neuml/txtai#egg=txtai[graph]"
]
},
{
@@ -296,7 +294,7 @@
"outputs": [],
"source": [
"from txtai import LLM\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\")"
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")"
]
},
{
-2
View File
@@ -21,8 +21,6 @@
"source": [
"# External vectorization\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"Vectorization is the process of transforming data into numbers using machine learning models. Input data is run through a model and fixed dimension vectors are returned. These vectors can then be loaded into a vector database for similarity search.\n",
"\n",
"txtai is an open-source first system. Given it's own open-source roots, like-minded projects such as [sentence-transformers](https://github.com/UKPLab/sentence-transformers) are prioritized during development. But that doesn't mean txtai can't work with Embeddings API services.\n",
@@ -8,8 +8,6 @@
"source": [
"# Build knowledge graphs with LLM-driven entity extraction\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"Embeddings databases are a union of vector indexes (sparse and dense), graph networks and relational databases. This enables vector search with SQL, topic modeling, retrieval augmented generation and more.\n",
"\n",
"Up until txtai 7.0, semantic graphs only supported automatic relationship detection. Now relationships can be loaded directly into a txtai database. This notebook will demonstrate how to work with this new feature."
@@ -35,7 +33,7 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[graph] autoawq"
"!pip install git+https://github.com/neuml/txtai#egg=txtai[graph]"
]
},
{
@@ -99,7 +97,7 @@
"from txtai import LLM\n",
"\n",
"# Load LLM\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\")\n",
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")\n",
"\n",
"data = []\n",
"for result in results:\n",
@@ -8,8 +8,6 @@
"source": [
"# Advanced RAG with graph path traversal\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"Embeddings databases are a union of vector indexes (sparse and dense), graph networks and relational databases. This enables vector search with SQL, topic modeling, retrieval augmented generation (RAG) and more.\n",
"\n",
"A standard RAG process typically runs a single vector search query and returns the closest matches. Those matches are then passed into a LLM prompt and used to limit the context and help ensure more factually correct answers are generated. This works well with most simple cases. More complex use cases, require a more advanced approach.\n",
@@ -37,7 +35,7 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[graph] autoawq"
"!pip install git+https://github.com/neuml/txtai#egg=txtai[graph]"
]
},
{
@@ -215,7 +213,7 @@
"source": [
"from txtai import LLM\n",
"\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\")"
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")"
]
},
{
@@ -280,6 +278,27 @@
"print(rag(\"Write a book covering the end of Roman Britain, Saxons, Vikings and Norman conquest of England\", context))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_It's important to note that txtai has multiple ways to run LLM inference. In the past, prior to \"Chat Templates\", it was expected that the submitted text had all the required chat tokens embedded. The same prompt above can also be written with chat messages. This is especially important when working with LLM APIs (i.e. OpenAI, Claude, Bedrock etc)._\n",
"\n",
"```python\n",
"llm([\n",
" {\"role\": \"system\": \"You are a friendly assistant. You answer questions from users.\"}\n",
" {\"role\": \"user\", \"content\": f\"\"\"\n",
" Answer the following question using only the context below. Only include information specifically discussed.\n",
"\n",
" question: {question}\n",
" context: {text} \n",
" \"\"\"}\n",
"])\n",
"```\n",
"\n",
"_See the [LLM pipeline documentation](https://neuml.github.io/txtai/pipeline/text/llm/) for more information._"
]
},
{
"cell_type": "markdown",
"metadata": {
+2 -2
View File
@@ -54,7 +54,7 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[api,graph,pipeline-train] datasets autoawq"
"!pip install git+https://github.com/neuml/txtai#egg=txtai[api,graph,pipeline-train] datasets"
]
},
{
@@ -244,7 +244,7 @@
"source": [
"from txtai import LLM\n",
"\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\")\n",
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")\n",
"\n",
"def rag(question, text):\n",
" prompt = f\"\"\"<|im_start|>system\n",
@@ -8,8 +8,6 @@
"source": [
"# Advanced RAG with guided generation\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"A standard RAG process typically runs a single vector search query and returns the closest matches. Those matches are then passed into a LLM prompt and used to limit the context and help ensure more factually correct answers are generated. This works well with most simple cases. More complex use cases, require a more advanced approach.\n",
"\n",
"This notebook will demonstrate how constrained or guided generation can be applied to better control LLM output."
@@ -35,7 +33,7 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai autoawq outlines"
"!pip install git+https://github.com/neuml/txtai#egg=txtai outlines"
]
},
{
@@ -59,7 +57,7 @@
"source": [
"from txtai import LLM\n",
"\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\")\n",
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")\n",
"\n",
"def rag(question, text):\n",
" prompt = f\"\"\"<|im_start|>system\n",
@@ -21,8 +21,6 @@
"source": [
"# Integrate txtai with Postgres\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"The default persistence methods for txtai are local and file-based. `SQLite` for content, `Faiss` for vectors and `NetworkX` for graph data. The main value add of txtai is getting up and running quickly with a minimal amount of external dependencies.\n",
"\n",
"Another key feature of txtai is being able to quickly move from prototyping to production. This notebook will demonstrate how txtai can integrate with [Postgres](https://www.postgresql.org/), a powerful, production-ready and open source object-relational database system. After txtai persists content to Postgres, we'll show it can be directly queried with SQL from any Postgres client 🔥"
@@ -8,8 +8,6 @@
"source": [
"# RAG with llama.cpp and external API services\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"txtai has been and always will be a local-first framework. It was originally designed to run models on local hardware using Hugging Face Transformers. As the AI space has evolved over the last year, so has txtai. Additional LLM inference frameworks have been available for a while using llama.cpp and external API services (via LiteLLM). Recent changes have added the ability to use these frameworks for vectorization and made it easier to use for LLM inference.\n",
"\n",
"This notebook will demonstrate how to run retrieval-augmented-generation (RAG) processes (vectorization and LLM inference) with llama.cpp and external API services."
@@ -182,7 +180,7 @@
"from txtai import LLM\n",
"\n",
"# LLM instance\n",
"llm = LLM(path=\"TheBloke/Mistral-7B-OpenOrca-GGUF/mistral-7b-openorca.Q4_K_M.gguf\")\n",
"llm = LLM(path=\"unsloth/Qwen3-4B-Instruct-2507-GGUF/Qwen3-4B-Instruct-2507-Q4_K_M.gguf\")\n",
"\n",
"# Question and context\n",
"question = \"Write a list of invented electric-powered devices\"\n",
@@ -237,11 +235,11 @@
"\n",
"# Download models\n",
"!wget https://huggingface.co/second-state/All-MiniLM-L6-v2-Embedding-GGUF/resolve/main/all-MiniLM-L6-v2-Q4_K_M.gguf\n",
"!wget https://huggingface.co/TheBloke/Mistral-7B-OpenOrca-GGUF/resolve/main/mistral-7b-openorca.Q4_K_M.gguf\n",
"!wget https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF/blob/main/Qwen3-4B-Instruct-2507-Q4_K_M.gguf\n",
"\n",
"# Start local API services\n",
"!nohup python -m llama_cpp.server --n_gpu_layers -1 --model all-MiniLM-L6-v2-Q4_K_M.gguf --host 127.0.0.1 --port 8000 &> vector.log &\n",
"!nohup python -m llama_cpp.server --n_gpu_layers -1 --model mistral-7b-openorca.Q4_K_M.gguf --chat_format chatml --host 127.0.0.1 --port 8001 &> llm.log &\n",
"!nohup python -m llama_cpp.server --n_gpu_layers -1 --model Qwen3-4B-Instruct-2507-Q4_K_M.gguf --chat_format chatml --host 127.0.0.1 --port 8001 &> llm.log &\n",
"!sleep 30"
]
},
+31 -5
View File
@@ -8,8 +8,6 @@
"source": [
"# How RAG with txtai works\n",
"\n",
"[txtai](https://github.com/neuml/txtai) is an all-in-one embeddings database for semantic search, LLM orchestration and language model workflows.\n",
"\n",
"Large Language Models (LLMs) have captured the public's attention with their impressive capabilities. The Generative AI era has reached a fever pitch with some predicting the coming rise of superintelligence.\n",
"\n",
"LLMs are far from perfect though and we're still a ways away from true AI. The biggest challenge is with hallucinations. Hallucinations is the term for when a LLM generates output that is factually incorrect. The alarming part of this is that on a cursory glance, it actually sounds like factual content. The default behavior of LLMs is to produce plausible answers even when no plausible answer exists. LLMs are not great at saying I don't know.\n",
@@ -45,7 +43,7 @@
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[api,pipeline] autoawq"
"!pip install git+https://github.com/neuml/txtai#egg=txtai[api,pipeline]"
]
},
{
@@ -74,7 +72,7 @@
"embeddings.load(provider=\"huggingface-hub\", container=\"neuml/txtai-wikipedia\")\n",
"\n",
"# Create LLM\n",
"llm = LLM(\"TheBloke/Mistral-7B-OpenOrca-AWQ\")"
"llm = LLM(\"Qwen/Qwen3-4B-Instruct-2507\")"
]
},
{
@@ -186,6 +184,27 @@
"id": "CSNbxxIMN_26"
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_Before continuing, it's important to note that txtai has multiple ways to run LLM inference. In the past, prior to \"Chat Templates\", it was expected that the submitted text had all the required chat tokens embedded. The same prompt above can also be written with chat messages. This is especially important when working with LLM APIs (i.e. OpenAI, Claude, Bedrock etc)._\n",
"\n",
"```python\n",
"llm([\n",
" {\"role\": \"system\": \"You are a friendly assistant. You answer questions from users.\"}\n",
" {\"role\": \"user\", \"content\": f\"\"\"\n",
" Answer the following question using only the context below. Only include information specifically discussed.\n",
"\n",
" question: {question}\n",
" context: {text} \n",
" \"\"\"}\n",
"])\n",
"```\n",
"\n",
"_See the [LLM pipeline documentation](https://neuml.github.io/txtai/pipeline/text/llm/) for more information._"
]
},
{
"cell_type": "markdown",
"source": [
@@ -259,6 +278,13 @@
}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_As with the LLM pipeline, the RAG pipeline also supports chat messages. See the [RAG pipeline documentation](https://neuml.github.io/txtai/pipeline/text/rag/) for more._"
]
},
{
"cell_type": "markdown",
"source": [
@@ -282,7 +308,7 @@
"\n",
"# RAG pipeline configuration\n",
"rag:\n",
" path: TheBloke/Mistral-7B-OpenOrca-AWQ\n",
" path: Qwen/Qwen3-4B-Instruct-2507\n",
" output: flatten\n",
" template: |\n",
" <|im_start|>system\n",
@@ -0,0 +1,569 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"gpuClass": "standard",
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# Embeddings index format for open data access\n",
"\n",
"The main programming language with txtai is Python. A key tenet is that the underlying data in an embeddings index is accessible without txtai.\n",
"\n",
"This notebook will demonstrate this through a series of examples.\n"
],
"metadata": {
"id": "-xU9P9iSR-Cy"
}
},
{
"cell_type": "markdown",
"source": [
"# Install dependencies\n",
"\n",
"Install `txtai` and all dependencies."
],
"metadata": {
"id": "shlUi2kKS7KT"
}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "xEvX9vCpn4E0"
},
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[graph] datasets sqlite-vec"
]
},
{
"cell_type": "markdown",
"source": [
"# Load dataset\n",
"\n",
"This example will use the `chatgpt-prompts` dataset."
],
"metadata": {
"id": "408IyXzKFSiG"
}
},
{
"cell_type": "code",
"source": [
"from datasets import load_dataset\n",
"\n",
"dataset = load_dataset(\"fka/awesome-chatgpt-prompts\", split=\"train\")"
],
"metadata": {
"id": "IQ_ns6YvFRm1"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Build an Embeddings index\n",
"\n",
"Let's first build an embeddings index using txtai."
],
"metadata": {
"id": "AtEdP7Utw3mk"
}
},
{
"cell_type": "code",
"source": [
"from txtai import Embeddings\n",
"\n",
"embeddings = Embeddings()\n",
"embeddings.index((x[\"act\"], x[\"prompt\"]) for x in dataset)\n",
"embeddings.save(\"txtai-index\")"
],
"metadata": {
"id": "DPWrubv5oOn7"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Let's take a look at the index that was created"
],
"metadata": {
"id": "0zrjOl6JtPI2"
}
},
{
"cell_type": "code",
"source": [
"!ls -l txtai-index\n",
"!echo\n",
"!file txtai-index/*"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "i7PN9itKtIyx",
"outputId": "ac904afb-83a8-4c5f-cf62-f5340225b8ac"
},
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"total 268\n",
"-rw-r--r-- 1 root root 342 Sep 6 15:21 config.json\n",
"-rw-r--r-- 1 root root 262570 Sep 6 15:21 embeddings\n",
"-rw-r--r-- 1 root root 2988 Sep 6 15:21 ids\n",
"\n",
"txtai-index/config.json: JSON data\n",
"txtai-index/embeddings: data\n",
"txtai-index/ids: data\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"The txtai embeddings index format is documented [here](https://neuml.github.io/txtai/embeddings/format/). Looking at the files above, we have configuration, embeddings data and ids storage. Ids storage is only used when content is disabled.\n",
"\n",
"Let's inspect each file."
],
"metadata": {
"id": "hx8H0dpXtX5b"
}
},
{
"cell_type": "code",
"source": [
"import json\n",
"\n",
"with open(\"txtai-index/config.json\") as f:\n",
" print(json.dumps(json.load(f), sort_keys=True, indent=2))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "h0yrQ8rqtnzh",
"outputId": "3379ab18-1805-4ef1-b946-1a61d18522db"
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{\n",
" \"backend\": \"faiss\",\n",
" \"build\": {\n",
" \"create\": \"2024-09-06T15:21:11Z\",\n",
" \"python\": \"3.10.12\",\n",
" \"settings\": {\n",
" \"components\": \"IDMap,Flat\"\n",
" },\n",
" \"system\": \"Linux (x86_64)\",\n",
" \"txtai\": \"7.5.0\"\n",
" },\n",
" \"dimensions\": 384,\n",
" \"offset\": 170,\n",
" \"path\": \"sentence-transformers/all-MiniLM-L6-v2\",\n",
" \"update\": \"2024-09-06T15:21:11Z\"\n",
"}\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import faiss\n",
"\n",
"index = faiss.read_index(\"txtai-index/embeddings\")\n",
"print(f\"Total records {index.ntotal}\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "-aqiqfqeuM5p",
"outputId": "4b7856f0-ec8d-4960-a419-e88a14d988a8"
},
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Total records 170\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import msgpack\n",
"\n",
"with open(\"txtai-index/ids\", \"rb\") as f:\n",
" print(msgpack.unpack(f)[5:10])"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "I0ffDyJsunrW",
"outputId": "d8c5072d-d181-46e1-fc1a-cc713a78e69f"
},
"execution_count": 18,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"['JavaScript Console', 'Excel Sheet', 'English Pronunciation Helper', 'Spoken English Teacher and Improver', 'Travel Guide']\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"Each file can be read without txtai. [JSON](https://www.json.org/json-en.html), [MessagePack](https://msgpack.org/index.html) and [Faiss](https://github.com/facebookresearch/faiss) all have libraries in multiple programming languages."
],
"metadata": {
"id": "0e3dpAFuvP-_"
}
},
{
"cell_type": "markdown",
"source": [
"# Embeddings index with SQLite\n",
"\n",
"In the next example, we'll use SQLite to store content and vectors courtesy of the [sqlite-vec](https://github.com/asg017/sqlite-vec) library."
],
"metadata": {
"id": "UUwk13mzwUTS"
}
},
{
"cell_type": "code",
"source": [
"from txtai import Embeddings\n",
"\n",
"embeddings = Embeddings(content=True, backend=\"sqlite\")\n",
"embeddings.index((x[\"act\"], x[\"prompt\"]) for x in dataset)\n",
"embeddings.save(\"txtai-sqlite\")"
],
"metadata": {
"id": "Z80FWhuNwj14"
},
"execution_count": 8,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Let's once again explore the generated index files."
],
"metadata": {
"id": "Kxcm42rixAH0"
}
},
{
"cell_type": "code",
"source": [
"!ls -l txtai-sqlite\n",
"!echo\n",
"!file txtai-sqlite/*"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "PEHT6LqHw_lw",
"outputId": "81d707dd-9760-40cd-e0b2-be43c26ba2d1"
},
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"total 1696\n",
"-rw-r--r-- 1 root root 384 Sep 6 15:21 config.json\n",
"-rw-r--r-- 1 root root 126976 Sep 6 15:21 documents\n",
"-rw-r--r-- 1 root root 1605632 Sep 6 15:21 embeddings\n",
"\n",
"txtai-sqlite/config.json: JSON data\n",
"txtai-sqlite/documents: SQLite 3.x database, last written using SQLite version 3037002, file counter 1, database pages 31, cookie 0x1, schema 4, UTF-8, version-valid-for 1\n",
"txtai-sqlite/embeddings: SQLite 3.x database, last written using SQLite version 3037002, file counter 1, database pages 392, cookie 0x1, schema 4, UTF-8, version-valid-for 1\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"This time note how there is a documents file with content stored in SQLite and a separate SQLite file for embeddings. Let's test it out."
],
"metadata": {
"id": "UXiKSG0JxLPo"
}
},
{
"cell_type": "code",
"source": [
"embeddings.search(\"teacher\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "VYMTXtUpxSLd",
"outputId": "6259f3c2-6a76-434d-d40f-f11cb2e63c80"
},
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[{'id': 'Math Teacher',\n",
" 'text': 'I want you to act as a math teacher. I will provide some mathematical equations or concepts, and it will be your job to explain them in easy-to-understand terms. This could include providing step-by-step instructions for solving a problem, demonstrating various techniques with visuals or suggesting online resources for further study. My first request is \"I need help understanding how probability works.\"',\n",
" 'score': 0.3421396017074585},\n",
" {'id': 'Educational Content Creator',\n",
" 'text': 'I want you to act as an educational content creator. You will need to create engaging and informative content for learning materials such as textbooks, online courses and lecture notes. My first suggestion request is \"I need help developing a lesson plan on renewable energy sources for high school students.\"',\n",
" 'score': 0.3267676830291748},\n",
" {'id': 'Philosophy Teacher',\n",
" 'text': 'I want you to act as a philosophy teacher. I will provide some topics related to the study of philosophy, and it will be your job to explain these concepts in an easy-to-understand manner. This could include providing examples, posing questions or breaking down complex ideas into smaller pieces that are easier to comprehend. My first request is \"I need help understanding how different philosophical theories can be applied in everyday life.\"',\n",
" 'score': 0.30780404806137085}]"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "markdown",
"source": [
"The top N results as expected. Let's again inspect the files."
],
"metadata": {
"id": "R0zsQx37xjWz"
}
},
{
"cell_type": "code",
"source": [
"import json\n",
"\n",
"with open(\"txtai-sqlite/config.json\") as f:\n",
" print(json.dumps(json.load(f), sort_keys=True, indent=2))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jDvH6dHrxqwf",
"outputId": "dcce1647-0488-4f3e-dba0-667a932bad27"
},
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{\n",
" \"backend\": \"sqlite\",\n",
" \"build\": {\n",
" \"create\": \"2024-09-06T15:21:13Z\",\n",
" \"python\": \"3.10.12\",\n",
" \"settings\": {\n",
" \"sqlite\": \"3.37.2\",\n",
" \"sqlite-vec\": \"v0.1.1\"\n",
" },\n",
" \"system\": \"Linux (x86_64)\",\n",
" \"txtai\": \"7.5.0\"\n",
" },\n",
" \"content\": true,\n",
" \"dimensions\": 384,\n",
" \"offset\": 170,\n",
" \"path\": \"sentence-transformers/all-MiniLM-L6-v2\",\n",
" \"update\": \"2024-09-06T15:21:13Z\"\n",
"}\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import sqlite3, sqlite_vec\n",
"\n",
"db = sqlite3.connect(\"txtai-sqlite/documents\")\n",
"print(db.execute(\"SELECT COUNT(*) FROM sections\").fetchone()[0])\n",
"\n",
"db = sqlite3.connect(\"txtai-sqlite/embeddings\")\n",
"db.enable_load_extension(True)\n",
"sqlite_vec.load(db)\n",
"print(db.execute(\"SELECT COUNT(*) FROM vectors\").fetchone()[0])"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "AsalQ-uUxxO0",
"outputId": "2a0e303e-e10e-424c-a952-e473d86cd2db"
},
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"170\n",
"170\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"As in the previous example, each file can be read without txtai. [JSON](https://www.json.org/json-en.html), [SQLite](https://www.sqlite.org/) and [sqlite-vec](https://github.com/asg017/sqlite-vec) all have libraries in multiple programming languages."
],
"metadata": {
"id": "Fo7XEUNny6s5"
}
},
{
"cell_type": "markdown",
"source": [
"# Graph storage\n",
"\n",
"Starting with txtai 7.4, graphs are stored using MessagePack. The indexed file has a list of nodes and edges that can easily be imported."
],
"metadata": {
"id": "Ipu08WhL0j6p"
}
},
{
"cell_type": "code",
"source": [
"from txtai import Embeddings\n",
"\n",
"embeddings = Embeddings(content=True, backend=\"sqlite\", graph={\"approximate\": False})\n",
"embeddings.index((x[\"act\"], x[\"prompt\"]) for x in dataset)\n",
"embeddings.save(\"txtai-graph\")"
],
"metadata": {
"id": "cmFiae6j0wHz"
},
"execution_count": 13,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!ls -l txtai-graph\n",
"!echo\n",
"!file txtai-graph/*"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hnv82EAB059Q",
"outputId": "454b263b-8733-4997-eb6e-7d585cfa32c6"
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"total 1816\n",
"-rw-r--r-- 1 root root 454 Sep 6 15:21 config.json\n",
"-rw-r--r-- 1 root root 126976 Sep 6 15:21 documents\n",
"-rw-r--r-- 1 root root 1605632 Sep 6 15:21 embeddings\n",
"-rw-r--r-- 1 root root 119970 Sep 6 15:21 graph\n",
"\n",
"txtai-graph/config.json: JSON data\n",
"txtai-graph/documents: SQLite 3.x database, last written using SQLite version 3037002, file counter 1, database pages 31, cookie 0x1, schema 4, UTF-8, version-valid-for 1\n",
"txtai-graph/embeddings: SQLite 3.x database, last written using SQLite version 3037002, file counter 1, database pages 392, cookie 0x1, schema 4, UTF-8, version-valid-for 1\n",
"txtai-graph/graph: data\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import msgpack\n",
"\n",
"with open(\"txtai-graph/graph\", \"rb\") as f:\n",
" data = msgpack.unpack(f)\n",
" print(data.keys())\n",
"\n",
" for key in data:\n",
" if data[key]:\n",
" print(key, data[key][100])"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Bx3Tzt3l08R3",
"outputId": "662d157c-6912-4626-db64-d959c2719331"
},
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"dict_keys(['nodes', 'edges', 'categories', 'topics'])\n",
"nodes [100, {'id': 'Ascii Artist', 'text': 'I want you to act as an ascii artist. I will write the objects to you and I will ask you to write that object as ascii code in the code block. Write only ascii code. Do not explain about the object you wrote. I will say the objects in double quotes. My first object is \"cat\"'}]\n",
"edges [5, 100, {'weight': 0.39010339975357056}]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# Wrapping up\n",
"\n",
"This notebook gave an overview of the txtai embeddings index file format and how it supports open data access.\n",
"\n",
"While txtai can be used as an all-in-one embeddings database, it can also be used for only one part of the stack such as data ingestion. For example, it can be used to populate a Postgres or SQLite database for downstream use. The options are there."
],
"metadata": {
"id": "y7N-YZlR5S-0"
}
}
]
}
+260
View File
@@ -0,0 +1,260 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Speech to Speech RAG\n",
"\n",
"There are many articles, notebooks and examples covering how to perform vector search and/or retrieval augmented generation (RAG) with txtai. A lesser known component of txtai is it's built-in workflow component.\n",
"\n",
"Workflows are a simple yet powerful construct that takes a callable and returns elements. Workflows enable efficient processing of pipeline data. Workflows are streaming by nature and work on data in batches. This allows large volumes of data to be processed efficiently.\n",
"\n",
"This notebook will demonstrate how to to build a Speech to Speech (S2S) workflow with txtai.\n",
"\n",
"_Note: This process is intended to run on local machines due to it's use of input and output audio devices._"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Install dependencies\n",
"\n",
"Install `txtai` and all dependencies."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline-audio]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Define the S2S RAG Workflow\n",
"\n",
"The next section defines the Speech to Speech (S2S) RAG workflow. The objective of this workflow is to respond to a user request in near real-time.\n",
"\n",
"txtai supports workflow definitions in Python and with YAML. We'll cover both methods.\n",
"\n",
"The S2S workflow below starts with a microphone pipeline, which streams and processes input audio. The microphone pipeline has voice activity detection (VAD) built-in. When speech is detected, the pipeline returns the captured audio data. Next, the speech is transcribed to text and then passed to a RAG pipeline prompt. Finally, the RAG result is run through a text to speech (TTS) pipeline and streamed to an output audio device."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"\n",
"from txtai import Embeddings, RAG\n",
"from txtai.pipeline import AudioStream, Microphone, TextToSpeech, Transcription\n",
"from txtai.workflow import Workflow, StreamTask, Task\n",
"\n",
"# Enable DEBUG logging\n",
"logging.basicConfig()\n",
"logging.getLogger().setLevel(logging.DEBUG)\n",
"\n",
"# Microphone\n",
"microphone = Microphone()\n",
"\n",
"# Transcription\n",
"transcribe = Transcription(\"distil-whisper/distil-large-v3\")\n",
"\n",
"# Embeddings database\n",
"embeddings = Embeddings()\n",
"embeddings.load(provider=\"huggingface-hub\", container=\"neuml/txtai-wikipedia\")\n",
"\n",
"# Define prompt template\n",
"template = \"\"\"\n",
"Answer the following question using only the context below. Only include information\n",
"specifically discussed. Answer the question without explaining how you found the answer.\n",
"\n",
"question: {question}\n",
"context: {context}\"\"\"\n",
"\n",
"# Create RAG pipeline\n",
"rag = RAG(\n",
" embeddings,\n",
" \"Qwen/Qwen3-4B-Instruct-2507\",\n",
" system=\"You are a friendly assistant. You answer questions from users.\",\n",
" template=template,\n",
" context=10\n",
")\n",
"\n",
"# Text to speech\n",
"tts = TextToSpeech(\"neuml/vctk-vits-onnx\")\n",
"\n",
"# Audio stream\n",
"audiostream = AudioStream()\n",
"\n",
"# Define speech to speech workflow\n",
"workflow = Workflow(tasks=[\n",
" Task(action=microphone),\n",
" Task(action=transcribe, unpack=False),\n",
" StreamTask(action=lambda x: rag(x, maxlength=4096, stream=True), batch=True),\n",
" StreamTask(action=lambda x: tts(x, stream=True, speaker=15), batch=True),\n",
" StreamTask(action=audiostream, batch=True)\n",
"])\n",
"\n",
"while True:\n",
" print(\"Waiting for input...\")\n",
" list(workflow([None]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Given that the input and outputs are audio, you'll have to use your imagination if you're reading this as an article.\n",
"\n",
"[Check out this video](https://www.youtube.com/watch?v=tH8QWwkVMKA) to see the workflow in action! The following examples are run:\n",
"\n",
"- Tell me about the Roman Empire\n",
"- Explain how faster than light travel could work\n",
"- Write a short poem about the Vikings\n",
"- Tell me about the Roman Empire in French"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# S2S Workflow in YAML\n",
"\n",
"A crucial feature of txtai workflows is that they can be defined with YAML. This enables building workflows in a low-code and/or no-code setting. These YAML workflows can then be \"dockerized\" and run.\n",
"\n",
"Let's define the same workflow below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%writefile s2s.yml\n",
"# Microphone\n",
"microphone:\n",
"\n",
"# Transcription\n",
"transcription:\n",
" path: distil-whisper/distil-large-v3\n",
"\n",
"# Embeddings database\n",
"cloud:\n",
" provider: huggingface-hub\n",
" container: neuml/txtai-wikipedia\n",
"\n",
"embeddings:\n",
"\n",
"# RAG\n",
"rag:\n",
" path: \"Qwen/Qwen3-4B-Instruct-2507\"\n",
" system: You are a friendly assistant. You answer questions from users.\n",
" template: |\n",
" Answer the following question using only the context below. Only include information\n",
" specifically discussed. Answer the question without explaining how you found the answer.\n",
"\n",
" question: {question}\n",
" context: {context}\n",
" context: 10\n",
"\n",
"# TTS\n",
"texttospeech:\n",
" path: neuml/vctk-vits-onnx\n",
"\n",
"# AudioStream\n",
"audiostream:\n",
"\n",
"# Speech to Speech Chat workflow\n",
"workflow:\n",
" s2s:\n",
" tasks:\n",
" - microphone\n",
" - action: transcription\n",
" unpack: False\n",
" - task: stream\n",
" action: rag\n",
" args:\n",
" maxlength: 4096\n",
" stream: True\n",
" batch: True\n",
" - task: stream\n",
" action: texttospeech\n",
" args:\n",
" stream: True\n",
" speaker: 15\n",
" batch: True\n",
" - task: stream\n",
" action: audiostream\n",
" batch: True"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from txtai import Application\n",
"\n",
"app = Application(\"s2s.yml\")\n",
"while True:\n",
" print(\"Waiting for input...\")\n",
" list(app.workflow(\"s2s\", [None]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once again, the same idea, just a different way to do it. In the video demo, the following query was asked.\n",
"\n",
"- As a Patriots fan, who would you guess is my favorite quarterback of all time is?\n",
"- I'm tall and run fast, what do you think the best soccer position for me is?\n",
"- I run slow, what do you think the best soccer position for me is?\n",
"\n",
"With YAML workflows, it's possible to fully define the process outside of code such as with a web interface. Perhaps someday we'll see this with [txtai.cloud](https://txtai.cloud) 😀"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Wrapping up\n",
"\n",
"This notebook demonstrated how to build a Speech to Speech (S2S) workflow with txtai. While the workflow uses an off-the-shelf embeddings database, a custom embeddings database can easily be swapped in. From there, we have S2S with our own data!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "local",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.20"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

Some files were not shown because too many files have changed in this diff Show More