Following the guide in AshAi
I get this error when I am trying to use the cosine distance between the vector and the embedded question, I have the same code as the guide
36 Replies
Add
"vector"
extension and follow these steps: https://hexdocs.pm/ash_postgres/AshPostgres.Extensions.Vector.html
If you get a chance, a PR to enhance that guide would be great.I did that
π€
I added the pgvector extension
can I see how you're calling it?
π€ does that resource have
AshPostgres.DataLayer
as its data layer?yes
and I have the AshAi, AshOban extensions
That is very very strange...
yes it is
the thing is that I copy pasted it from the guide
π€ right.
What if you comment out the sort/filter
I created the index and used the vectorize block
is it just one of them breaking it?
tried it with one of them off and it still
failed
I commented the filter/sort same thing
wait with both commented out you still get that error?
or just with one or the other
no
only when there is one of them
from the message it says it can't find the vector_cosine_distance
Is this something you can push up somewhere we can check out?
I don't think I will be able to
but I will try to check if I can get it to work using PSQL
oh, wiat
lemme see your repo
I just added pgvector rn and recompiling
now it works
still no vectors match but no errors
I get a not found so that's fixed
thanks a lot. it's been a roller coaster (first time using it) using the library but the support has been great
@Zach Daniel now there is a weird issue if I add pgvector to the extension it will force me to migrate and this won't work the user doesn't have super user privileges, and if I remove it I can't search
do I need to install the elixir pgvector package
It's just called "vector"
Not "pgvector"
Does our guide say "pgvector"?
the guide doesn't mention anything
ok so I changed it to vector and created the postgres_types.ex file as per the steps mentioned here, the issue is that there is no mention that this is required, also I installed AshAi chat using igniter
Gotcha, can you please open an issue or PR describing what was missing? This will fix it for the next folks πββοΈ
I will do that, I will be traveling this weekend, I will do it in monday
one last question does ashai create a column to mark whether the vector contains stale embedding
because it's been 2 hours and 300k embedding tasks, and the vectors are still being embeded

the issue is that the vectors were embedded, I am afraid to look at my openai bill
π
it should be scheduling embeddings whenever the values change
You should of course trial these things before running them on real data...
I know it shouldn't, anyway thank you great library. I will write a PR+Issue on monday for the guide.
Is there something in the roadmap about including real vector dbs currently postgres is complaining about the vector size if I use open ai's text-embedding-3-large which is 3072
Also Can a resource have multiple vectorize statements? I tried but failed miserably.
I will probably keep a list of items that I missed from the guide so new comers won't fall into them
only one vectorize statement but you can vectorize multiple attributes
vectorize foo: :bar, baz: :buz
IIRC
for doing it without pgvector everything gets more complicated
but also: you can definitely do it with a vector size that big
I would always prefer to use pgvector if possible before reaching for a "real" vector dbcan you expand on this
Sorry, its like this:
so you can vectorize multiple attrs
Maybe I didn't understand what you wanted though
how do I define the text that will be vectorized for each one
π€ what do you mean?
That takes the
name
attribute, and vectorizes it as vectorized_name
so you'd just set the name
attributeoh that will do it actually
I thought that I need to define full_text function for each attribute
so I can still use the full_text one if I want to concat multiple values
but I can only have one full_text function
Ah, yeah currently
ok thank you