8000 Add F# sample by kant2002 · Pull Request #82 · neon-sunset/Pinecone.NET · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add F# sample #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2023
Merged

Add F# sample #82

merged 2 commits into from
Dec 12, 2023

Conversation

kant2002
Copy link
Contributor
@kant2002 kant2002 commented Dec 4, 2023

No description provided.

@neon-sunset
Copy link
Owner

Thanks!

@neon-sunset
Copy link
Owner

You mentioned implicit conversions warnings. Could you post them here? I'd like to look into that.

@kant2002
Copy link
Contributor Author
kant2002 commented Dec 4, 2023
Warning	FS3391	This expression uses the implicit conversion 'MetadataValue.op_Implicit(value: bool) : MetadataValue' to convert type 'bool' to type 'MetadataValue'. See https://aka.ms/fsharp-implicit-convs. This warning may be disabled using '#nowarn "3391".	Example.FSharp	C:\d\github\Pinecone.NET\example\Example.FSharp\Program.fs	24	Active	

image

@neon-sunset
Copy link
Owner
neon-sunset commented Dec 4, 2023

Thanks. Because MetadataValue is effectively a DU (null | bool | double | string | MetadataMap | Seq<MetadataValue>), another option that can be explored is exposing a proper F# type conversion to/from that but that would probably require either referencing an F# dependency in the main project or creating a new project that will do that just to make the compiler happy for this specific case. I wonder if there are other ways to prevent the warning from being raised without user intervention (I've skimmed through the document at the link but it was not immediately obvious).

@kant2002
Copy link
Contributor Author
kant2002 commented Dec 4, 2023

I think having small assembly Pinecone.FSharp is fine which can provide tailored experience is well known pattern. That way you can have idiomatic API in both languages.

// Free tier is limited to 1 index only
let indexName = "test-index"
let! indexList = pinecone.ListIndexes()
if not (indexList |> Array.contains indexName) then
Copy link

Choose a reason for hiding this comment

8000

The reason will be displayed to describe this comment to others. Learn more.

I prefer indexList |> Array.contains indexName |> not


// Query the index by embedding and metadata filter
let! results = index.Query((Array.zeroCreate<float32> 1536), 3u, filter = priceRange, includeMetadata = true)
let tt = results |> Seq.collect (fun v -> v.Metadata)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used

// Query the index by embedding and metadata filter
let! results = index.Query((Array.zeroCreate<float32> 1536), 3u, filter = priceRange, includeMetadata = true)
let tt = results |> Seq.collect (fun v -> v.Metadata)
printfn "%s" (results |> Seq.collect (fun v -> v.Metadata) |> Seq.map string |> String.concat "\n")
Copy link
@Lanayx Lanayx Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write this as

results 
|> Seq.collect _.Metadata 
|> Seq.map string 
|> String.concat "\n"
|> printfn "%s"

printfn "%s" (results |> Seq.collect (fun v -> v.Metadata) |> Seq.map string |> String.concat "\n")

// Remove the example vectors we just added
do! index.Delete(["first"; "second"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Square brackets are not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work without them. Maybe due to overloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you was talking about round brackets?

do! index.Update("second", metadata = createMetadata["price", 99])

// Query the index by embedding and metadata filter
let! results = index.Query((Array.zeroCreate<float32> 1536), 3u, filter = priceRange, includeMetadata = true)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is float32 required?

use! index = pinecone.GetIndex(indexName)

let tags = [|"tag1" ; "tag2"|]
let first: Vector = Vector(Id = "first", Values = Array.zeroCreate 1536, Metadata = createMetadata["new", true; "price", 50; "tags", tags])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like type specitifcation is not required

@kant2002
Copy link
Contributor Author

@neon-sunset can you please take a look?

@neon-sunset neon-sunset merged commit 5c78d5a into neon-sunset:main Dec 12, 2023
@neon-sunset
Copy link
Owner

@kant2002 @Lanayx Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0