Skip to content

Commit d877e77

Browse files
Query tools vector store
1 parent dfed5c4 commit d877e77

File tree

18 files changed

+455
-11
lines changed

18 files changed

+455
-11
lines changed

dev/insert_tool.clj

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(ns insert-tool
2+
(:require
3+
[babashka.process :as process]
4+
[cheshire.core :as json]
5+
[clojure.string :as string]))
6+
7+
(comment
8+
;; query
9+
;; score is distance so lower is closer
10+
(->
11+
(deref
12+
(process/process
13+
{:cwd "/Users/slim/docker/labs-ai-tools-for-devs/tools_vector_store/"
14+
:out :string
15+
:err :string}
16+
"docker"
17+
"run"
18+
"--rm"
19+
"-e" (format "OPENAI_API_KEY=%s" (string/trim (slurp "/Users/slim/.openai-api-key")))
20+
"-v" (format "%s:%s" "/Users/slim/docker/labs-ai-tools-for-devs/tools_vector_store/chroma_db" "/app/chroma_db")
21+
"vonwig/tools-vector-store:local" "hola"
22+
))
23+
:out
24+
(json/parse-string true)
25+
))
26+
27+
(defn insert []
28+
;; insert
29+
(deref
30+
(process/process
31+
{:cwd "/Users/slim/docker/labs-ai-tools-for-devs/tools_vector_store/"
32+
:out :string
33+
:err :string}
34+
"docker"
35+
"run"
36+
"--rm"
37+
"--entrypoint" "python"
38+
"-e" (format "OPENAI_API_KEY=%s" (string/trim (slurp "/Users/slim/.openai-api-key")))
39+
"-v" (format "%s:%s" "/Users/slim/docker/labs-ai-tools-for-devs/tools_vector_store/chroma_db" "/app/chroma_db")
40+
"vonwig/tools-vector-store:local" "insert.py"
41+
)))

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
# our application makes calls to the curl binary
7171
# therefore, wrap the custom-jdk in a script with curl in the PATH
7272
entrypoint = pkgs.writeShellScriptBin "entrypoint" ''
73-
export PATH=${pkgs.lib.makeBinPath [pkgs.curl]}
73+
export PATH=${pkgs.lib.makeBinPath [pkgs.curl pkgs.git]}
7474
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
7575
${custom-jdk}/bin/agent-graph "$@"
7676
'';

graphs/prompts/journals/2024_09_03.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@
4646
- if the project being analyzed is located somewhere other than $PWD then the `--host-dir` will need to be updated.
4747
- [[Running the Prompt Engine]]
4848
- [[Authoring Prompts]]
49-
- Here is a prompt file with lots of non-default metadata (it uses [extractors]([[Prompt Extractors]]), a [[tool]], and uses a local llm in [[ollama]]). It uses one system prompt, and one user prompt. Note that the user prompt contains a moustache template to pull data in from an extractor.
49+
- ---
5050
id:: 66d7f3ff-8769-40b3-b6b5-fc4fceea879e
51-
52-
```md
53-
---
5451
extractors:
5552
- name: linguist
5653
image: vonwig/go-linguist:latest
@@ -87,6 +84,4 @@
8784
This project contains {{language}} code.
8885
{{/linguist}}
8986

90-
Can you find any language specific project files and list them?
91-
92-
```
87+
Can you find any language specific project files and list them?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [langchain adapter for sqlitevec](https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/vectorstores/sqlitevec.py) #link
2+
- this imports the `sqlite3` and `sqlite_vec` python packages. At connection time, we use `sqlite_vec` to load the vector extensions into sqlite.
3+
-

src/graph.clj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@
106106
calls)
107107
(async/reduce conj []))))})))
108108

109+
(defn tools-query
110+
[_]
111+
(async/go {}))
112+
109113
(declare stream chat-with-tools)
110114

111115
; tool_calls are maps with an id and a function with arguments an name
@@ -192,9 +196,11 @@
192196
(add-node "tool" tool)
193197
(add-node "end" end)
194198
(add-node "sub-graph" sub-graph)
195-
(add-edge "start" "completion")
196-
(add-edge "tool" "completion")
197-
(add-edge "sub-graph" "completion")
199+
(add-node "tools-query" tools-query)
200+
(add-edge "start" "tools-query")
201+
(add-edge "tool" "tools-query")
202+
(add-edge "sub-graph" "tools-query")
203+
(add-edge "tools-query" "completion")
198204
(add-conditional-edges "completion" tool-or-end)))
199205

200206
(comment

tools_vector_store/.dockerignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
6+
7+
**/.DS_Store
8+
**/__pycache__
9+
**/.venv
10+
**/.classpath
11+
**/.dockerignore
12+
**/.env
13+
**/.git
14+
**/.gitignore
15+
**/.project
16+
**/.settings
17+
**/.toolstarget
18+
**/.vs
19+
**/.vscode
20+
**/*.*proj.user
21+
**/*.dbmdl
22+
**/*.jfm
23+
**/bin
24+
**/charts
25+
**/docker-compose*
26+
**/compose*
27+
**/Dockerfile*
28+
**/node_modules
29+
**/npm-debug.log
30+
**/obj
31+
**/secrets.dev.yaml
32+
**/values.dev.yaml
33+
LICENSE
34+
README.md
35+
# Include any files or directories that you don't want to be copied to your
36+
# container here (e.g., local build artifacts, temporary files, etc.).
37+
#
38+
# For more help, visit the .dockerignore file reference guide at
39+
# https://docs.docker.com/go/build-context-dockerignore/
40+
41+
**/.DS_Store
42+
**/__pycache__
43+
**/.venv
44+
**/.classpath
45+
**/.dockerignore
46+
**/.env
47+
**/.git
48+
**/.gitignore
49+
**/.project
50+
**/.settings
51+
**/.toolstarget
52+
**/.vs
53+
**/.vscode
54+
**/*.*proj.user
55+
**/*.dbmdl
56+
**/*.jfm
57+
**/bin
58+
**/charts
59+
**/docker-compose*
60+
**/compose.y*ml
61+
**/Dockerfile*
62+
**/node_modules
63+
**/npm-debug.log
64+
**/obj
65+
**/secrets.dev.yaml
66+
**/values.dev.yaml
67+
LICENSE
68+
README.md

tools_vector_store/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

tools_vector_store/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM python:3.12.6-slim AS base
4+
5+
# Prevents Python from writing pyc files.
6+
ENV PYTHONDONTWRITEBYTECODE=1
7+
8+
# Keeps Python from buffering stdout and stderr to avoid situations where
9+
# the application crashes without emitting any logs due to buffering.
10+
ENV PYTHONUNBUFFERED=1
11+
12+
ENV OPENAI_API_KEY=""
13+
14+
WORKDIR /app
15+
16+
# Create a non-privileged user that the app will run under.
17+
# See https://docs.docker.com/go/dockerfile-user-best-practices/
18+
ARG UID=10001
19+
RUN adduser \
20+
--disabled-password \
21+
--gecos "" \
22+
--home "/nonexistent" \
23+
--shell "/sbin/nologin" \
24+
--no-create-home \
25+
--uid "${UID}" \
26+
appuser
27+
28+
# Download dependencies as a separate step to take advantage of Docker's caching.
29+
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
30+
# Leverage a bind mount to requirements.txt to avoid having to copy them into
31+
# into this layer.
32+
RUN --mount=type=cache,target=/root/.cache/pip \
33+
--mount=type=bind,source=requirements.txt,target=requirements.txt \
34+
python -m pip install -r requirements.txt
35+
36+
# Switch to the non-privileged user to run the application.
37+
USER appuser
38+
39+
# Copy the source code into the container.
40+
COPY ./*.py .
41+
42+
ENTRYPOINT ["python","query.py"]

tools_vector_store/derivation.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ lib, python3Packages, sqlite-vec }:
2+
with python3Packages;
3+
buildPythonApplication rec {
4+
pname = "vectorstore";
5+
version = "0.1.0";
6+
src = ./.;
7+
dependencies = [
8+
setuptools
9+
];
10+
propagatedBuildInputs = [langchain langchain-community langchain-openai sqlite-vec];
11+
nativeCheckInputs = [pytest];
12+
checkPhase = ''
13+
'';
14+
build-system = [
15+
setuptools
16+
];
17+
}
18+

0 commit comments

Comments
 (0)